From e34017a8dc1264749024d4ab5317879a1fc0582d Mon Sep 17 00:00:00 2001 From: "Shawn David Pringle, B.Sc" Date: Tue, 2 Apr 2024 00:39:58 -0300 Subject: [PATCH] * Corrected value for max_int64. If you run a 32-bit interpreter to bootstrap a code base to 64-bit. The interpreter has BITS32 set, but the translator uses BITS64. The translator uses the 64-bits values but its constants have been folded by a 32-bit interpreter. Certain values like 2^62-1 + 1 get folded but not promoted to doubles because of the imprecise nature of the interpreter using the MAXINT constant in the translator. The code will use a smaller number so that the numbers are promoted early on in the translator C code to avoid erroneous folding in code it translates. You should later translate Euphoria interpreter and translator again with the newly created 64-bit translator in order to make sure it uses INT_ATOMS more. --- source/global.e | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/source/global.e b/source/global.e index c0e1dabc7..482509550 100644 --- a/source/global.e +++ b/source/global.e @@ -256,16 +256,12 @@ export enum export constant max_int32 = #3FFFFFFF -ifdef not EU4_0 then - atom ptr = machine_func( 16, 8 ) - poke( ptr, { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f } ) - export constant - max_int64 = peek8s( ptr ) - machine_proc( 17, ptr ) -elsedef - export constant - max_int64 = 0x3fffffffffffffff -end ifdef +-- When building on 64-bit but with a 32-bit interpreter numbers are misread +-- with rounding errors by the interpreter trying to interpret a 64-bit instance +-- of the translator. So, depending on that round off error, we will use a much +-- smaller maximum integer, so the code will always work. Note BITS64 and friends +-- do not help you here. +export constant max_int64 = (0x4000_0000_0000_0000 = 0x3fff_ffff_ffff_ffff) * power(2,51) + (0x4000_0000_0000_0000 != 0x3fff_ffff_ffff_ffff) * power(2,62) - 1 ifdef BITS64 then export constant