Faculty of Information Technology
Software Engineering Group

Opened 3 months ago

Last modified 7 weeks ago

#288 new defect

Float exponent is not compatible with other dialects (VW, Squeak, Dolphin, ...)

Reported by: nicolas.cellier.aka.nice@… Owned by:
Priority: major Milestone:
Component: default Keywords: Float exponent
Cc: Also affects CVS HEAD (eXept version): no

Description

Currently, exponent and mantissa are defined in term of frexp() function.

They return a significand in interval [0.5,1.0) and exponent accordingly.

Other dialects return the significand in interval [1.0,2.0).
Because they are defined in term of ilogb()/scalb() function.

Thus 1.0 exponent is 1 in stx and 0 in other dialects, making port of some library more difficult than necessary.

I would rather use ilogb() and scalb() for the exponent because they also work if ever the radix of Float implementation is not 2.

There is no sender of exponent/mantissa in base image, so this should be a safe change.

Change History (4)

comment:1 Changed 3 months ago by nicolas.cellier.aka.nice@…

More over, exponents also should be compatible with emin and emax

    | fmax |
    fmax := (2.0 nextFloat: -1) timesTwoPower: Float emax.
    self assert: (fmax nextFloat: 1) isInfinite.
    fmax exponent > Float emax
        ifTrue: [self halt: 'How a Float exponent could be greater than maximum Float exponent, emax?'].


comment:2 Changed 3 months ago by Jan Vrany

Hi,

nice to see you here!

Now I must admit that I never touched this code nor I feel an expert in FP. What you say makes sense - I have no problem changing #exponent and #mantissa (or any other FP-related code given the change is justified - your word is enough :-) - and accompanied with tests).

Can you provide some tests to star with, or/and (even better) a proposal for a fix?

comment:3 Changed 7 weeks ago by nicolas.cellier.aka.nice@…

Beware, there are two sets of standards:

IEEE 754 defines:
float = sign * significand * (radix raisedTo: exponent)
where 1 <= significand, significand < radix for normalized floats

ISO/IEC 10967 defines:
float = sign * fraction * (radix raisedTo: exponent)
where radix reciprocal <= fraction, fraction < 1.

So obviously the exponent differ by 1 in the two models!
For ieee754, exponent is (self abs log: Float radix) floor (the ilogb function)
For ISO-10967, exponent is (self abs log: Float radix) floor + 1. (the frexp)

See for example ISO/IEC 10967 (Language Independent Arithmetic (LIA))
http://www.open-std.org/jtc1/sc22/wg11/docs/n507.pdf draft for part I
http://www.open-std.org/JTC1/SC22/WG11/docs/n462.pdf draft for part II

But in both models, the mininum and maximum exponent should fit definitions of emin and emax:
page 54 of first draft (10967-1) for IEEE754 model
page 64 of first draft for second model

Float fminNormalized exponent = Float emin.
Float fmax exponent = Float emax.
Float fminDenormalized exponent = (Float emin - Float precision + 1).
Float fminNormalized predecessor exponent = (Float emin - 1).

We must either implement one model, or the other, but not something inconsistent.
Squeak and VW are implementing significand/exponent and have emin=-1022 emax=1023 for double precision, thus my suggestion, even if it does not fit ISO-10967 definition...

comment:4 Changed 7 weeks ago by nicolas.cellier.aka.nice@…

BTW, mantissa is ambiguous See https://en.wikipedia.org/wiki/Mantissa
It could be interpreted as fraction part of logarithm!
For this reason, significand is the preferred term nowadays.

Note: See TracTickets for help on using tickets.