in reply to Re: Integer vs Float during addition
in thread Integer vs Float during addition
Which outputs:use warnings; use Devel::Peek; $int = 17; #print "\$int: $int\n"; Dump($int); print "##############\n\n"; $double_1 = 1.23456789; #print "\$double_1: $double_1\n"; Dump($double_1); print "##############\n\n"; $double_2 = 1.0000; #print "\$double_2: $double_2\n"; Dump($double_2); print "##############\n\n"; $ul = 2 ** 31 + 16; # too big for an IV #print "\$ul: $ul\n"; Dump($ul); print "##############\n\n"; $double_3 = 2 ** 46 + 19; # too big for a UV or IV #print "\$double_3: $double_3\n"; Dump($double_3); print "##############\n\n"; $int += 0.0123; # $int no longer an IV #print "\$int: $int\n"; Dump($int); print "##############\n\n";
Note that $double_2 (assigned a value of 1.000) is an NV (perl's idea of a double) as you expected, but the actual value in the NV slot has been truncated to simply '1' ... when you 'print $double_2;', it's the value in the NV slot that gets printed.D:\pscrpt>perl try.pl SV = IV(0x89c7cc) at 0x3f5d3c REFCNT = 1 FLAGS = (IOK,pIOK) IV = 17 ############## SV = NV(0x8afcb4) at 0x3f5d24 REFCNT = 1 FLAGS = (NOK,pNOK) NV = 1.23456789 ############## SV = NV(0x8afcbc) at 0x8a3204 REFCNT = 1 FLAGS = (NOK,pNOK) NV = 1 ############## SV = IV(0x89c7c8) at 0x8ba4d8 REFCNT = 1 FLAGS = (IOK,pIOK,IsUV) UV = 2147483664 ############## SV = NV(0x8afcc4) at 0x8a2fdc REFCNT = 1 FLAGS = (NOK,pNOK) NV = 70368744177683 ############## SV = PVNV(0x3f8714) at 0x3f5d3c REFCNT = 1 FLAGS = (NOK,pNOK) IV = 17 NV = 17.0123 PV = 0 ##############
|
|---|