Re: double val to long val conversion issue
| From: | Remi Collet | Date: | Sun, 10 Feb 2013 15:19:46 +0000 |
| Subject: | Re: double val to long val conversion issue | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-65757@lists.php.net to get a copy of this message | ||
Le 10/02/2013 15:58, Gustavo Lopes a écrit :
> If we want to eliminate the undefined behavior, we should do (on archs
> with 64-bit longs):
>
> (long)(unsigned long)(fmod(d, pow(2., 64.)))
>
> Can you test this program on ppc64:
$ gcc -O3 -lm conv.c && ./a.out 9223372036854775808
-9223372036854775808 -9223372036854775808
$ gcc -O3 -lm conv.c && ./a.out 4e21
-2943463994972700672 -1
$ gcc -O3 -lm conv.c && ./a.out 4e19
3106511852580896768 -1
> I get this:
> $ gcc -O3 -lm conv.c && ./a.out 9223372036854775808
> -9223372036854775808 -9223372036854775808
> $ gcc -O3 -lm conv.c && ./a.out 4e21
> -2943463994972700672 0
> $ gcc -O3 -lm conv.c && ./a.out 4e19
> 3106511852580896768 0
Remi.