[squeak-dev] fdlibm 1.0 exp is not the closest approximation of E

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Mon Dec 27 22:04:45 UTC 2010


2010/12/27 Igor Stasenko <siguctua at gmail.com>:
> On 27 December 2010 20:09, Nicolas Cellier
> <nicolas.cellier.aka.nice at gmail.com> wrote:
>> It seems that
>>    1.0 exp = (Float classPool at: #E)
>> is now false with the fdlibm version, at leat on Cog/MacOSX.
>>
>
> tried on both John's 5.8b12
> and own-built Cog VM , it returns true in both cases.
> Maybe my image is obsolete and E is different there?
>
> (Float classPool at: #E) at: 1
> 1074118410
>
> (Float classPool at: #E) at: 2
>  2333366121
>

Hi Igor,
your E seems correct.
You can simply use (Float classPool at: #E) hex.

Do you have the FloatMathPlugin plugged in your image ?
In my trunk, Float>>exp is defined like this:

exp
	"Answer E raised to the receiver power.
	 Optional. See Object documentation whatIsAPrimitive."

	<primitive: 'primitiveExp' module: 'FloatMathPlugin'>
	self isNaN ifTrue:[SignalNaN ifTrue:[NaNError signal]. ^self].
	"For now, fall back to the Squeak version of exp if FloatMathPlugin is absent"
	^self primitiveExp

The old primitive works OK for exp(1.0) :
    1.0 primitiveExp hex = (Float classPool at: #E) hex

>> (Float classPool at: #E) is the closest Float approximation of e,
>> which you can check with:
>> (1.0 asArbitraryPrecisionFloatNumBits: 200) exp asFloat = (Float
>> classPool at: #E)
>>
>> It's bad that fdlibm be able to compute (1.0e32 cos) with less than
>> 1/2 ulp error, but (1.0 exp) with more than 1/2 ulp !
>>
>
> Nicolas, how about writing own float math plugin?
> You , among all of us seems care about float math most. So how about
> getting your hands dirty with some C hacking?
> :)
>

You mean rewriting fdlibm ? Less fun than writing in Smalltalk !

Nicolas



More information about the Squeak-dev mailing list