[Oberon] Upper limit of FLOOR
Hans Klaver
hklaver at dds.nl
Mon Jan 16 19:47:12 CET 2023
On 16 Jan. 2023, at 14:18 joerg.straube at iaeth.ch wrote:
> The limit of 2^24-1 makes somehow sense as you normally expect FLOOR(FLT(x)) = x
For reasons of symmetry and inverse operations this indeed makes sense.
> As the mantissa of a REAL is only 24 bits, all REALs larger than 2^24 are not exact:
> As r := 2000000000.0 and r := 2000000189.0 have the same binary representation, FLOOR would return to all REALs in between the same value.
You are right.
I did not realise that OBNC must make use of a 64-bit floating point type for REAL and a 32-bit type for INTEGER.
It certainly helps to have a list ready for all these limits you have to deal with.
For that I prepared Limits.Mod.
Thanks,
Hans
> One of the gotcha's I encountered while trying to improve Texts.WriteRealFix was that in PO the standard function procedure FLOOR overflows for values > 16777215.00 (2^24-1) and not, as I expected, only for values > 2147483647.00 (2^31-1). I guess I'm not the only one who is surprised by this (see for instance: https://lists.inf.ethz.ch/pipermail/oberon/2020/015013.html).
>
> Some other Oberon-07 compilers (e.g. OBNC) do not have this limit.
>
> For FLT I can understand the limit of 16777215 because larger integers do not always have an exact floating point representation. For FLOOR there is no parallel argument: every REAL up to 2147483647.00 can unequivocally be transferred to a 32-bit INTEGER.
>
> So why this limit? Does anyone have an opinion on this?
>
> If you would like to test these limits, you can use procedure TestRealIO.FltFloor which can be found here:https://github.com/hansklav/Oberon-REAL-IO/blob/main/TestRealIO.Mod
More information about the Oberon
mailing list