[Upd: This pertains to when using addition.] An int, yes. A float, no. Just like in C. Ints are promoted to floats, but floats aren't promoted to integers. You need to cast to int to get int behaviour. Just like in C.
use v5.14; use warnings; my $x = 2**53; say sprintf "%d", $x; say sprintf "%d", $x + 1; say sprintf "%d", int( $x ) + 1;
#include <inttypes.h> #include <stdint.h> #include <stdio.h> int main( void ) { double x = 9007199254740992; printf( "%"PRIu64"\n", (uint64_t)( x ) ); printf( "%"PRIu64"\n", (uint64_t)( x + 1 ) ); printf( "%"PRIu64"\n", (uint64_t)( (uint64_t)x + 1 ) ); }
9007199254740992 9007199254740992 9007199254740993
Other differences between floats and ints is the existence of inifinity, NaN and -0.
In reply to Re^4: Largest integer in 64-bit perl
by ikegami
in thread Largest integer in 64-bit perl
by harangzsolt33
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |