Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- large float's
February 23, 2006, 6:00 am
rate this thread
wikipedia.org offers more insight, suggesting that is, exactly,
0x7FEFFFFFFFFFFFFF. This sorta begs the question... how can this
number be represented in PHP without resorting to the decimal notation?
...doesn't work. Nor does...
So... any ideas as to what will work?
Re: large float's
The maximum floating-point value is platform dependent. For a 64-bit
platform, it's ~1.8e308, but for a 32-bit platform it's ~3.4e38
(assuming you're using the IEEE 754 standard).
This code converts from a hex-representation to a floating-point
representation (for 32-bit):
$dec = hexdec($strHex);
$sign = ($dec & (1 << SIGN_BIT)) != 0;
$exp = (($dec & ((2 << EXPONENT_MSB) - (1 << EXPONENT_LSB))) >>
- (1 << (EXPONENT_MSB - EXPONENT_LSB))
- (MANTISSA_MSB - MANTISSA_LSB);
$man = (($dec & ((2 << MANTISSA_MSB) - (1 << MANTISSA_LSB))) >>
+ (2 << (MANTISSA_MSB - MANTISSA_LSB));
$float = floatval($man * pow(2, $exp) * ($sign ? -1 : 1));
For a 64-bit version, you'll need to alter the constants; you can get
the required values from
Note that this code doesn't deal with special cases, i.e. NaN, infinity,