Search code examples
floating-pointhexieee-754conventionsnotation

What does "p" stand for in the exponential hex notation for floats


In hex notation, the number 40.0 is written 0x1.4000000000000p+5 meaning (1 + 4/16) * 2⁵.

What does the p stand-for? Presumably, that letter was chosen for a reason.


Solution

  • It simply means "power"

    By convention, the letter P (or p, for "power") represents times two raised to the power of, whereas E (or e) serves a similar purpose in decimal as part of the E notation. The number after the P is decimal and represents the binary exponent. Increasing the exponent by 1 multiplies by 2, not 16. 10.0p1 = 8.0p2 = 4.0p3 = 2.0p4 = 1.0p5. Usually, the number is normalized so that the leading hexadecimal digit is 1 (unless the value is exactly 0).

    https://en.wikipedia.org/wiki/Hexadecimal#Hexadecimal_exponential_notation

    P was chosen because E is a valid hexadecimal digits so it may appear in the significand part