Endian check for a Mac - help requested
David T. Lewis
lewis at mail.msen.com
Wed Sep 29 09:15:03 UTC 2004
On Wed, Sep 29, 2004 at 01:23:19PM +1200, Richard A. O'Keefe wrote:
> "David T. Lewis" <lewis at mail.msen.com> asked:
> Could somebody with a Mac (big endian machine)
> please evaluate the following
>
> { SmalltalkImage current endianness . Float nan at: 1 . Float nan at: 2 }
>
> Answer:
> #(#big 2146959360 0)
>
> In principle, knowing the order of bytes within a word _still_ leaves you
> ignorant of whether the word order for a double matches the byte order for
> a word. There have been machines where that was a serious issue, but I
> don't know if Squeak runs on any such.
>
Thanks Richard, that's the issue I am worried about. For the NaN equality
test, I'm looking for a reliable way to produce two instances of Float NaN
with different bit patterns, see:
[FIX][BUG] Float NaN's ( another patch to replace #testNaN2 )
The concern would be that some future flavor of Squeak platform with 64
bit word size might produce a Float NaN with results similar to this:
#(#big 0 2146959360)
... in which case the "improved" test would break, adding to the general
confusion for folks moving Squeak to that platform. If you have a chance,
could you please have a look at the #testNaN2 that I posted, and see if
it looks safe and/or correct?
Thanks.
Dave
The test is:
testNaN2
"Two NaN values are always considered to be different.
On an little-endian machine (32 bit Intel), Float nan is 16rFFF80000 16r00000000.
On a big-endian machine (PowerPC), Float nan is 16r7FF80000 16r00000000. Changing
the bit pattern of the first word of a NaN produces another value that is still
considered equal to NaN. This test should work on both little endian and big
endian machines."
"FloatTest new testNaN2"
| nan1 nan2 |
nan1 := Float nan copy.
nan2 := Float nan copy.
"test two instances of NaN with the same bit pattern"
self deny: nan1 = nan2.
self deny: nan1 == nan2.
self deny: nan1 = nan1.
self assert: nan1 == nan1.
"change the bit pattern of nan1"
self assert: nan1 size == 2.
self assert: (nan1 at: 2) = 0.
nan1 at: 1 put: (nan1 at: 1) + 999.
self assert: nan1 isNaN.
self assert: nan2 isNaN.
self deny: (nan1 at: 1) = (nan2 at: 1).
"test two instances of NaN with different bit patterns"
self deny: nan1 = nan2.
self deny: nan1 == nan2.
self deny: nan1 = nan1.
self assert: nan1 == nan1
More information about the Squeak-dev
mailing list
|