32-bit to 16-bit Floating Point Conversion

Complete conversion from single precision to half precision. This is a direct copy from my SSE version, so it’s branch-less. It makes use of the fact that -true == ~0 to preform branchless selections (GCC converts if statements into an unholy mess of conditional jumps, while Clang just converts them to conditional moves.) Update (2019-11-04): … Read more

Why is Number.MAX_SAFE_INTEGER 9,007,199,254,740,991 and not 9,007,199,254,740,992?

I would say its because while Math.pow(2, 53) is the largest directly representable integer, its unsafe in that its also the first value who’s representation is also an approximation of another value: 9007199254740992 == 9007199254740993 // true In contrast to Math.pow(2, 53) – 1: 9007199254740991 == 9007199254740993 // false

Why does division by zero in IEEE754 standard results in Infinite value?

It’s a nonsense from the mathematical perspective. Yes. No. Sort of. The thing is: Floating-point numbers are approximations. You want to use a wide range of exponents and a limited number of digits and get results which are not completely wrong. ๐Ÿ™‚ The idea behind IEEE-754 is that every operation could trigger “traps” which indicate … Read more

Double precision – decimal places

An IEEE double has 53 significant bits (that’s the value of DBL_MANT_DIG in <cfloat>). That’s approximately 15.95 decimal digits (log10(253)); the implementation sets DBL_DIG to 15, not 16, because it has to round down. So you have nearly an extra decimal digit of precision (beyond what’s implied by DBL_DIG==15) because of that. The nextafter() function … Read more

Why does MSVS not optimize away +0? [duplicate]

The compiler cannot eliminate the addition of a floating-point positive zero because it is not an identity operation. By IEEE 754 rules, the result of adding +0. to โˆ’0. is not โˆ’0.; it is +0. The compiler may eliminate the subtraction of +0. or the addition of โˆ’0. because those are identity operations. For example, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)