Re: literal 9223372036854775808 is negative

new topic     » goto parent     » topic index » view thread      » older message » newer message

As long as we are comparing languages. Python also does the right thing as evaluating the number as positive. Euphoria:

include std/io.e 
if 9223372036854775808 < 0 then 
  puts(io:STDOUT, "Euphoria: 9223372036854775808 is negative\n") 
end if 

Output:

Euphoria: 9223372036854775808 is negative 

Python:

if 9223372036854775808 < 0:  
  print("Python: 9223372036854775808 is negative\n") 
No Output. (Good)

Similar C + + fails to compile and gives the following error:

cpp.cpp:3:7: warning: integer constant is so large that it is unsigned 
    3 |   if (9223372036854775808 < 0) { 
      |       ^~~~~~~~~~~~~~~~~~~ 
 
The C + + code:
#include <iostream> 
int main() { 
  if (9223372036854775808 < 0) { 
    std::cout << "C++: 9223372036854775808 is negative\n"; 
  } 
} 

Although I think the C + + behavior is not really desirable, I prefer what it does to what Euphoria does right now.

The number is just outside of the range of what a 64-bit Integer can hold, but if it were a valid value, its binary representation would be the same as the one used for -9223372036854775808.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu