Skip to content

Commit

Permalink
* Corrected value for max_int64.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Shawn David Pringle, B.Sc committed Apr 2, 2024
1 parent 7bccc49 commit e34017a
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions source/global.e
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e34017a

Please sign in to comment.