I stumbled upon http://sourceware.org/ml/glibc-cvs/2013-q1/msg00115.html, which includes the line
#define TWO5 0x1.0p5 /* 2^5 */
Apparently, TWO5 is defined as a double with the explicit value 1<<5
. However, this is the first time I see this notation. How has this format been in use, and what is the advantage over just writing 2.5
?
To do so, floating-point uses a biased exponent, which is the original exponent plus a constant bias. 32-bit floating-point uses a bias of 127. For example, for the exponent 7, the biased exponent is 7 + 127 = 134 = 100001102. For the exponent −4, the biased exponent is: −4 + 127 = 123 = 011110112.
In computers, floating-point numbers are represented in scientific notation of fraction ( F ) and exponent ( E ) with a radix of 2, in the form of F×2^E . Both E and F can be positive as well as negative.
The biased exponent is used for the representation of negative exponents. The biased exponent has advantages over other negative representations in performing bitwise comparing of two floating point numbers for equality. The range of exponent in single precision format is -128 to +127.
There are two floating point primitive types. Data type float is sometimes called "single-precision floating point". Data type double has twice as many bits and is sometimes called "double-precision floating point".
This notation was introduced in C99. The advantage is that the value is expressed in hexadecimal form, so it is not subject to rounding etc. that occurs when you convert a floating-point value between the underlying representation and a decimal form.
There are plenty of pages that describe this notation, for example:
http://www.exploringbinary.com/hexadecimal-floating-point-constants/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With