gnudatalanguage / gdl

GDL - GNU Data Language
GNU General Public License v2.0
274 stars 61 forks source link

9223372036854775808 #1037

Closed fawltylanguage closed 2 years ago

fawltylanguage commented 3 years ago

9223372036854775808 is out of range for 64 bit signed integers. IDL accepts it and some popular IDL libraries use it, eg. Astrolib for fits reading.

A freshly compiled GDL gives different results if this number is used. I think this is a bug in IDL, but you may consider to 'fix' it in GDL for compatibility with IDL.

pro test_long64_maxp1
  help, -9223372036854775808
  help, -9223372036854775808ll

  help,  9223372036854775808
  help,  9223372036854775808ll

  help, long64('-9223372036854775808')
  help, long64(' 9223372036854775808')

  help, long64('-9223372036854775808ll')
  help, long64(' 9223372036854775808ll')

  help, long64(-9223372036854775808)
  help, long64( 9223372036854775808)

  help, long64(-9223372036854775808ll)
  help, long64( 9223372036854775808ll)

  help, ulong64('-9223372036854775808')
  help, ulong64(' 9223372036854775808')

  help, ulong64('-9223372036854775808ll')
  help, ulong64(' 9223372036854775808ll')

  help, ulong64(-9223372036854775808)
  help, ulong64( 9223372036854775808)

  help, ulong64(-9223372036854775808ll)
  help, ulong64( 9223372036854775808ll)
end
IDL> test_long64_maxp1
% Compiled module: TEST_LONG64_MAXP1.
<Expression>    LONG64    =   -9223372036854775808
<Expression>    LONG64    =   -9223372036854775808
<Expression>    LONG64    =   -9223372036854775808
<Expression>    LONG64    =   -9223372036854775808
<Expression>    LONG64    =   -9223372036854775808
<Expression>    LONG64    =   -9223372036854775808
<Expression>    LONG64    =   -9223372036854775808
<Expression>    LONG64    =   -9223372036854775808
<Expression>    LONG64    =   -9223372036854775808
<Expression>    LONG64    =   -9223372036854775808
<Expression>    LONG64    =   -9223372036854775808
<Expression>    LONG64    =   -9223372036854775808
<Expression>    ULONG64   =    9223372036854775808
<Expression>    ULONG64   =    9223372036854775808
<Expression>    ULONG64   =    9223372036854775808
<Expression>    ULONG64   =    9223372036854775808
<Expression>    ULONG64   =    9223372036854775808
<Expression>    ULONG64   =    9223372036854775808
<Expression>    ULONG64   =    9223372036854775808
<Expression>    ULONG64   =    9223372036854775808
IDL> 
GDL> test_long64_maxp1
% Compiled module: TEST_LONG64_MAXP1.
<Expression>    LONG64    =                      1
<Expression>    LONG64    =                      1
<Expression>    LONG64    =                     -1
<Expression>    LONG64    =                     -1
<Expression>    LONG64    =   -9223372036854775808
<Expression>    LONG64    =    9223372036854775807
<Expression>    LONG64    =   -9223372036854775808
<Expression>    LONG64    =    9223372036854775807
<Expression>    LONG64    =                      1
<Expression>    LONG64    =                     -1
<Expression>    LONG64    =                      1
<Expression>    LONG64    =                     -1
<Expression>    ULONG64   =    9223372036854775808
<Expression>    ULONG64   =    9223372036854775808
<Expression>    ULONG64   =    9223372036854775808
<Expression>    ULONG64   =    9223372036854775808
<Expression>    ULONG64   =                      1
<Expression>    ULONG64   =   18446744073709551615
<Expression>    ULONG64   =                      1
<Expression>    ULONG64   =   18446744073709551615
GDL>
GillesDuvert commented 3 years ago

It's an indirect result of #1086

GillesDuvert commented 3 years ago

For the record, it appears that the (ANTLR3) GDL interpreter treats all negative constants as a product: minus ("-") times whatever the following (positive) serie of [0..9] digits mean. i.e., only the absolute value of the numeric constant is compared to s,l,ll limits . This complicates a lot the problem as the special handling of limit cases as this one is to be done in the interpreter.

GillesDuvert commented 2 years ago

solved in #1204

fawltylanguage commented 2 years ago

Another variant:

IDL> help, 9223372036854775808u
<Expression>    ULONG64   =    9223372036854775808

GDL> help, 9223372036854775808u
% Unsigned integer constant must be less than 65536.

'u' denotes signedness, not size.