Question

  • Compiler: GCC 4.7.2(Debian 4.7.2-5)
  • Platform: Linux 3.2.0 x86 (Debian 7.1)

I am writing a string to integer conversion function and I read here that hexadecimal has it's own form of exponential notation. I have a couple questions regarding that.

  1. The article says that the value that follows the 'p' is a decimal not a hexadecimal is that correct?

  2. The article also says that power that comes after the 'p' has a base of 2 not 16 is that true?

  3. Is 0x1.11p4 an integer or does it have a fractional component?

And this leads to the main question: does octal have it's own form of exponential notation? If it does, what is the form?

If octal does not have it's own exponential notation, would it be reasonable to adapt the hexadecimal notation to octal strings as well?

Was it helpful?

Solution 2

I see you have a healthy mistrust of Wikipedia! =)

  1. Yes, the exponent is decimal.

  2. Yes, the base is 2, not 16.

  3. 0x1.11p4 is equivalent to 11.116 and is a float, not an integer.

I don't know of an octal form. If you wished to define your own I don't see a problem with that. Presumably you would use a 0 prefix instead of 0x and leave everything else the same. Obviously you can't write code with this representation, since the compiler doesn't support it.

OTHER TIPS

  • The value that follows the p is in decimal, but it represents an exponent with base 2.
  • 0x1.11p4 has a fractional component of .11 which is also in base 16.
  • There are no octal floating point constants, so you cannot use exponential notation with them.
  • To clarify with your example, 0x1.11p4 is 1.1116 × 24.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top