Converting Int to Bool

No, there is and has never been an explicit built in option for conversion of Int to Bool, see the language reference for Bool for details. There exists, still, however, an initializer by NSNumber. The difference is that implicit bridging between Swift numeric type and NSNumber has been removed in Swift 3 (which previously allowed …

Read more

cast variable to int vs round() function

In case of casting a float/double value to int, you generally loose the fractional part due to integer truncation. This is quite different from rounding as we would usually expect, so for instance 2.8 ends up as 2 with integer truncation, just as 2.1 would end up as 2. Update: Another source of potential (gross) …

Read more

How to properly instantiate os.FileMode

My fix has been to define my own constants as I couldn’t find any in os or syscall: const ( OS_READ = 04 OS_WRITE = 02 OS_EX = 01 OS_USER_SHIFT = 6 OS_GROUP_SHIFT = 3 OS_OTH_SHIFT = 0 OS_USER_R = OS_READ<<OS_USER_SHIFT OS_USER_W = OS_WRITE<<OS_USER_SHIFT OS_USER_X = OS_EX<<OS_USER_SHIFT OS_USER_RW = OS_USER_R | OS_USER_W OS_USER_RWX = OS_USER_RW …

Read more

unsigned int (c++) vs uint (c#)

C++ and C# are different languages. They have different rules for handling type promotion in the event of comparisons. In C++ and C, they’re usually compared as if they were both unsigned. This is called “unsigned preserving”. C++ and C compilers traditionally use “unsigned preserving” and the use of this is specified in the C++ …

Read more