1. power(2,63) is not equal to 9223372036854775808

Following on from this discussion about the tokeniser's handling of 9223372036854775808:

Euphoria Interpreter v4.1.0 development 
   64-bit Windows, Using System Memory 
   Revision Date: 2015-02-02 14:18:53, Id: 6300:57179171dbed 

print(1,  power(2,63) - 9223372036854775808) 

Should equal zero, right?

1.844674407e+019 
So until this is fixed we need to use power(2,63) instead of 9223372036854775808 on those rare occasions

new topic     » topic index » view message » categorize

2. Re: power(2,63) is not equal to 9223372036854775808

Even more interesting

print(1,  power(2,63) - 1 = 9223372036854775807) 
puts(1,"\n") 
print(1,  power(2,63) = 9223372036854775808) 
puts(1,"\n") 
print(1,  power(2,63) + 1 = 9223372036854775809) 
puts(1,"\n") 
print(1,  power(2,63) + 2 = 9223372036854775810) 

>eui bug.ex 
1 
0 
0 
1 

new topic     » goto parent     » topic index » view message » categorize

3. Re: power(2,63) is not equal to 9223372036854775808

Would be interesting to see if someone can reproduce this on *nix. Wonder if it's a MinGW bug.

If you have MinGW yourself, you could also try this C program, to see if the bug shows up by itself.

#include <stdio.h> 
#include <math.h> 
 
int main(int argc, char ** argv) 
{ 
        printf("%d\n", (powl(2.0L, 63.0L) - 1.0L) == 9223372036854775807.0L); 
        printf("%d\n", powl(2.0L, 63.0L) == 9223372036854775808.0L); 
        printf("%d\n", (powl(2.0L, 63.0L) + 1.0L) == 9223372036854775809.0L); 
        printf("%d\n", (powl(2.0L, 63.0L) + 2.0L) == 9223372036854775810.0L); 
 
        printf("%d\n", (pow(2.0, 63.0) - 1.0) == 9223372036854775807.0); 
        printf("%d\n", pow(2.0, 63.0) == 9223372036854775808.0); 
        printf("%d\n", (pow(2.0, 63.0) + 1.0) == 9223372036854775809.0); 
        printf("%d\n", (pow(2.0, 63.0) + 2.0) == 9223372036854775810.0); 
 
        printf("%d\n", (powl(2.0L, 63.0L) - 1.0L) == 9223372036854775807.0); 
        printf("%d\n", powl(2.0L, 63.0L) == 9223372036854775808.0); 
        printf("%d\n", (powl(2.0L, 63.0L) + 1.0L) == 9223372036854775809.0); 
        printf("%d\n", (powl(2.0L, 63.0L) + 2.0L) == 9223372036854775810.0); 
        return 0; 
} 
new topic     » goto parent     » topic index » view message » categorize

4. Re: power(2,63) is not equal to 9223372036854775808

Eui (and euc) give the same results on Linux 64 bit:

1 
0 
0 
1 

irv@irv-desktop:~$ gcc power.c -o power 
irv@irv-desktop:~$ ./power 
1 
1 
1 
1 
1 
1 
1 
1 
0 
1 
0 
0 
irv@irv-desktop:~$  

new topic     » goto parent     » topic index » view message » categorize

5. Re: power(2,63) is not equal to 9223372036854775808

WSLg Jammy on Windows 11

bugmagnet@LAPTOP-H6HBEGA9:/mnt/c/Users/bugma/Dropbox/Projects/exercism-dev/oe$ ./bug 
1 
1 
1 
1 
1 
1 
1 
1 
0 
1 
0 
0 

new topic     » goto parent     » topic index » view message » categorize

6. Re: power(2,63) is not equal to 9223372036854775808

Just so you know, the four tests in #2 above now seem to work on 64-bit Phix, producing 1,1,1,1, but you may need 1.0.5+

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu