[Vm-dev] cosine broken in all MacOSX squeak VM ???

Eliot Miranda eliot.miranda at gmail.com
Wed Dec 19 23:33:24 UTC 2012


Hi Nicholas,

    I'll take a look as soon as time allows.  I'm debugging a Newspeak
issue right now.


On Wed, Dec 19, 2012 at 1:34 PM, Nicolas Cellier <
nicolas.cellier.aka.nice at gmail.com> wrote:

>
> I just tried this a latest cog:
>
> (1 to: 300) collect: [:i | (10.0 raisedTo: i) sin squared + (10.0
> raisedTo: i) cos squared - 1 / Float epsilon]
> -> #(1.0 -21.0 -215.0 1951.0 -825.0 164322.0 2.991826e6 ...
>
> It sounds like incredibly high errors so soon...
>
> The sine is OK:
> (1 to: 300) collect: [:i | (10.0 raisedTo: i) sin - ((10.0 raisedTo:
> i) asArbitraryPrecisionFloatNumBits: 53) sin asFloat / ((10.0
> raisedTo: i) asArbitraryPrecisionFloatNumBits: 53) sin asFloat ulp]
> ->  #(-1.0 0.0 1.0 0.0 0.0 0.0 ...
>
> This is due to cosine:
> (1 to: 300) collect: [:i | (10.0 raisedTo: i) cos - ((10.0 raisedTo:
> i) asArbitraryPrecisionFloatNumBits: 53) cos asFloat / ((10.0
> raisedTo: i) asArbitraryPrecisionFloatNumBits: 53) cos asFloat ulp]
> -> #(-1.0 -24.0 -383.0 -2049.0 825.0 175417.0 -3.297612e6 ...
>
> Though, MacOSX math library is very robust and accurate even for Float
> fmax, this one works well:
>
> #include <stdio.h>
> #include <math.h>
> int main()
> {
>     int i;
>     double d,y;
>     for(i=1;i<301;i++) {
>         d=pow(10.0,i);
>         y=(cos(d)*cos(d)+sin(d)*sin(d)-1)/ldexp(1.0,-52);
>         printf("i=%d y=%.17f\n",i,y);
>     }
>     return 0;
> }
>
> $ gcc --version
> i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
> Copyright (C) 2007 Free Software Foundation, Inc.
>
> It sounds like sin is taken from one accurate library while cos is
> taken from an inacurrate one !!!
> For example it sounds like cos might well be using broken x86 fcos
> How can it be so?
> Can someone explain ?
>
> Virtual Machine
> ---------------
> /Users/nicolas/Smalltalk/Squeak/Cog.app/Contents/MacOS/Croquet
> Croquet Closure Cog VM [CoInterpreter VMMaker.oscog-eem.238] Croquet
> Cog 4.0.2637
> Mac OS X built on Dec 17 2012 19:54:57 Compiler: 4.2.1 (Apple Inc.
> build 5666) (dot 3)
> platform sources revision VM: r2637
> http://www.squeakvm.org/svn/squeak/branches/Cog Plugins: r2545
> http://squeakvm.org/svn/squeak/trunk/platforms/Cross/plugins
> CoInterpreter VMMaker.oscog-eem.238 uuid:
> a3d10eab-6079-4c91-99f6-3dcf58d1446f Dec 17 2012
> StackToRegisterMappingCogit VMMaker.oscog-eem.234 uuid:
> 66acafd1-cad0-4f20-b786-ab8f48201d82 Dec 17 2012
>
> Loaded VM Modules
> -----------------
> B2DPlugin VMMaker.oscog-eem.235 (i)
> BitBltPlugin VMMaker.oscog-eem.235 (i)
> DropPlugin VMMaker.oscog-eem.235 (i)
> FilePlugin VMMaker.oscog-eem.235 (i)
> FloatArrayPlugin VMMaker.oscog-eem.235 (e)
> InternetConfigPlugin VMMaker.oscog-eem.235 (i)
> LargeIntegers v1.5 VMMaker.oscog-eem.235 (i)
> Matrix2x3Plugin VMMaker.oscog-eem.235 (i)
> MiscPrimitivePlugin VMMaker.oscog-eem.235 (i)
> SecurityPlugin VMMaker.oscog-eem.235 (i)
> SocketPlugin VMMaker.oscog-eem.235 (i)
> ZipPlugin VMMaker.oscog-eem.235 (i)
> Same results with old VM
>
>
> Same result with old 4.2.5 VM !!!
>
> Virtual Machine
> ---------------
> /Users/nicolas/Smalltalk/Squeak/Squeak
> 4.2.5beta1U.app/Contents/MacOS/Squeak VM Opt
> Squeak4.1 of 17 April 2010 [latest update: #9957] Squeak VM 4.2.5b1
> Mac Carbon 4.2.5b1 15-Jun-10 >85D9C693-2A2A-4C33-B05C-C20B2A63B166<
> VMMaker versionString 4.2.4
>
> Loaded VM Modules
> -----------------
> B2DPlugin 15 June 2010 (i)
> BitBltPlugin 15 June 2010 (i)
> DropPlugin 15 June 2010 (i)
> FilePlugin 15 June 2010 (i)
> FloatArrayPlugin 15 June 2010 (i)
> InternetConfigPlugin 15 June 2010 (i)
> LargeIntegers v1.5 15 June 2010 (i)
> Matrix2x3Plugin 15 June 2010 (i)
> MiscPrimitivePlugin 15 June 2010 (i)
> SecurityPlugin 15 June 2010 (i)
> SocketPlugin 15 June 2010 (i)
> ZipPlugin 15 June 2010 (i)
>



-- 
best,
Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20121219/0e66abad/attachment.htm


More information about the Vm-dev mailing list