[M3devel] floating point : problem with Extended.m3

Mika Nystrom mika at async.caltech.edu
Sun Apr 3 03:52:08 CEST 2011


No it's fine with EXTENDED=LONGREAL (well as long as LONGREAL is 64 or 32
bits).

I'm really just curious what has to be changed to make EXTENDED not be
LONGREAL... probably many more things in the compiler?

    Mika

Tony Hosking writes:
>Are you saying it is broken with EXTENDED=LONGREAL?
>That is the current implementation.
>This code is heritage.  Not sure I understand all the implications.
>
>On Apr 2, 2011, at 9:28 PM, Mika Nystrom wrote:
>
>> Hello m3devel (mainly Tony),
>> 
>> I believe I've found a problem with float/Common/Extended.m3.
>> 
>> Doesn't the code assume that EXTENDED is a multiple of 32 bits wide?
>> 
>> That does not seem to me to be a safe assumption... in fact I don't
>> think it's even safe to round up.  EXTENDED could (and should) be
>> 10 bytes wide on most machines.  (I am aware that it is currently
>> the same as LONGREAL, but...)
>> 
>>     Mika
>> 
>>> UNSAFE MODULE Extended;
>>> 
>>> IMPORT Word, Int32;
>>> 
>>> PROCEDURE Equal(a, b: T): BOOLEAN =
>>>  BEGIN RETURN a = b END Equal;
>>> 
>>> 
>>> CONST Int32Sz = BYTESIZE(T) DIV BYTESIZE(Int32.T);
>>> 
>>> TYPE Int32Arr = ARRAY [0..Int32Sz-1] OF Int32.T;
>>> 
>>> PROCEDURE Hash(a: T): Word.T =
>>>  VAR arr := LOOPHOLE(a, Int32Arr); res := 0; BEGIN
>>>    FOR i := 0 TO LAST(arr) DO
>>>      res := Word.Xor(res, Int32.Hash(arr[i]))
>>>    END (* FOR *);
>>>    RETURN res
>>>  END Hash;
>>> 
>>> PROCEDURE Compare(a, b: T): [-1..1] =
>>>  BEGIN
>>>    IF a < b THEN RETURN -1
>>>    ELSIF a > b THEN RETURN 1
>>>    ELSE RETURN 0
>>>    END (* IF *)
>>>  END Compare;



More information about the M3devel mailing list