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

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Thu Dec 20 09:07:40 UTC 2012


Ah stupid me, this is not a VM problem !
Just a naive image side implementation

Float>>cos
	"Answer the cosine of the receiver taken as an angle in radians."

	^ (self + Halfpi) sin

Nicolas
2012/12/20 David T. Lewis <lewis at mail.msen.com>:
>
> Nicholas,
>
> If you have a chance, could you try this on an interpreter VM and see if
> you get the same results?
>
>    http://squeakvm.org/unix/release/Squeak-4.10.2.2614-darwin10.8.0_i386.tar.gz
>
> This does not sound like something that should be specific to Cog so I am
> expecting you would see the same issue on both VMs. If so, we can take
> a look at the plugin and see what is going on.
>
> Dave
>
>
> On Wed, Dec 19, 2012 at 03:33:24PM -0800, Eliot Miranda wrote:
>>
>> 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
>


More information about the Vm-dev mailing list