[squeak-dev] Re: ArbitraryPrecisionFloat ln and exp

nicolas cellier ncellier at ifrance.com
Sat Mar 22 20:07:18 UTC 2008

Andreas Raab a écrit :
> nicolas cellier wrote:
>> You could try using tests from ArbitraryPrecisionFloat at squeak 
>> source http://www.squeaksource.com/ArbitraryPrecisionFl/.
> One thing that was interesting when I was running the tests is that the 
> failed for both testExpLn and testLnVsFloat. It seems like either fdlibm 
>  or your code is off by one bit. For example:
> (1 asArbitraryPrecisionFloatNumBits: 53) exp asFloat hex
> => '4005BF0A8B145769'
> 1 asFloat exp hex
> => '4005BF0A8B14576A'
> (3 asArbitraryPrecisionFloatNumBits: 53) ln asFloat hex
> => '3FF193EA7AAD030B'
> 3 asFloat ln hex
> => '3FF193EA7AAD030A'
> Any ideas what could cause this? I would have expected these two to 
> agree on the result.
> Cheers,
>   - Andreas

On linux with libm.so.6
ldd `which squeak`
         linux-gate.so.1 =>  (0xffffe000)
         libutil.so.1 => /lib/libutil.so.1 (0xb7f4c000)
         libdl.so.2 => /lib/libdl.so.2 (0xb7f48000)
         libm.so.6 => /lib/i686/libm.so.6 (0xb7f23000)
         libnsl.so.1 => /lib/libnsl.so.1 (0xb7f0c000)
         libc.so.6 => /lib/i686/libc.so.6 (0xb7dcc000)

I have a good agreement on these:

1 asFloat exp hex. '4005BF0A8B145769'
3 asFloat ln hex. '3FF193EA7AAD030B'

This is consistent with ArbitraryPrecisionFloat if i extend precision:
(1 asArbitraryPrecisionFloatNumBits: 53+16) exp mantissa hex. 

The last 16 bits are 16r5356 < 16r8000, thus round to nearest even mode 
did round correctly to 69, only a ceiling mode (round toward infinity) 
would round to 6A.

Same with 3 ln:
(3 asArbitraryPrecisionFloatNumBits: 53+16) ln mantissa hex 

16r976A > 16r8000, thus round to nearest even does round to 30B, a floor 
mode (round toward negative infinity) or truncate mode (round toward 
zero) would give 30A.

It is as if fdlibm did always set Least Significant Bit to zero... A 
wrong interpretation of nearest even ?

Anyway, i do not always have a good agreement on larger Float cases...
It would be better to check against a multiple precision library like GMP.


More information about the Squeak-dev mailing list