Re: double val to long val conversion issue
| From: | Remi Collet | Date: | Sun, 10 Feb 2013 07:52:37 +0000 |
| Subject: | Re: double val to long val conversion issue | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-65751@lists.php.net to get a copy of this message | ||
One more test (to get rid of compiler optimization)
int main (int argc, char *argv[]) {
double d;
if (argc>1 && sscanf(argv[1], "%lg", &d)) {
printf(" double=%.20lg\n", d);
printf(" signed=%lx\n", (long)d);
printf("unsigned=%lx\n", (unsigned long)d);
}
return 0;
}
On x86_64 (so, with or without -O2)
$ gcc -O2 -Wall math2.c -o math2 && ./math2 9223372036854775807
double=9223372036854775808
signed=8000000000000000
unsigned=8000000000000000
On ppc64
$ gcc -O2 -Wall math2.c -o math2 && ./math2 9223372036854775807
double=9223372036854775808
signed=0x7fffffffffffff
unsigned=8000000000000000
Remi.