Are all integer values perfectly represented as doubles? [duplicate]

Disclaimer (as suggested by Toby Speight): Although IEEE 754 representations are quite common, an implementation is permitted to use any other representation that satisfies the requirements of the language. The doubles are represented in the form mantissa * 2^exponent, i.e. some of the bits are used for the non-integer part of the double number. bits … Read more

How to check if C++ compiler uses IEEE 754 floating point standard

Actually you have an easier way to achieve this in C++. From the C++ standard 18.2.1.1 the class numeric_limits exists within std. In order to access said static member you simply do this: std::numeric_limits<double>::is_iec559; Or: std::numeric_limits<float>::is_iec559; Which should return true if IEEE 754 is in use, false otherwise. As an alternative method, the second part … Read more

Read/Write bytes of float in JS

You can do it with typed arrays: var buffer = new ArrayBuffer(4); var intView = new Int32Array(buffer); var floatView = new Float32Array(buffer); floatView[0] = Math.PI console.log(intView[0].toString(2)); //bits of the 32 bit float Or another way: var view = new DataView(new ArrayBuffer(4)); view.setFloat32(0, Math.PI); console.log(view.getInt32(0).toString(2)); //bits of the 32 bit float Not sure what browser support … Read more

Algorithm to convert an IEEE 754 double to a string?

The code used by various software environments to convert floating-point numbers to string representations is typically based on the following publications (the work by Steele and White is particularly frequently cited): Jerome T. Coonen: “An Implementation Guide to a Proposed Standard for Floating-Point Arithmetic.” Computer, Vol. 13, No. 1, January 1980, pp. 68-79 Guy. L. … Read more

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