in reply to Re: Strange behaviour when printing certain numeric values
in thread Strange behaviour when printing certain numeric values
# with my Ubuntu system perl v5.26.1 % perl -MDevel::Peek -wle 'for(0x1p+60, 0x1p+60, 0x1p+60) { Dump($_); +print $_ + 1; Dump($_) }' SV = NV(0x558a66569f70) at 0x558a66569f88 REFCNT = 2 FLAGS = (NOK,READONLY,PROTECT,pNOK) NV = 1.15292150460685e+18 1.15292150460685e+18 SV = PVNV(0x558a665410f0) at 0x558a66569f88 REFCNT = 2 FLAGS = (NOK,READONLY,PROTECT,pIOK,pNOK) IV = 1152921504606846976 NV = 1.15292150460685e+18 PV = 0 SV = NV(0x558a66569f88) at 0x558a66569fa0 REFCNT = 2 FLAGS = (NOK,READONLY,PROTECT,pNOK) NV = 1.15292150460685e+18 1152921504606846977 SV = NV(0x558a66569f88) at 0x558a66569fa0 REFCNT = 2 FLAGS = (NOK,READONLY,PROTECT,pNOK) NV = 1.15292150460685e+18 SV = NV(0x558a6656a018) at 0x558a6656a030 REFCNT = 2 FLAGS = (NOK,READONLY,PROTECT,pNOK) NV = 1.15292150460685e+18 1152921504606846977 SV = NV(0x558a6656a018) at 0x558a6656a030 REFCNT = 2 FLAGS = (NOK,READONLY,PROTECT,pNOK) NV = 1.15292150460685e+18
So a) it is a different scalar coming in each time; b) the contents of the scalar on entry to the loop are identical each time (at least as far as Devel::Peek is showing). Perversely, the first time it shows as an NV and caches an IV value, whereas subsequently it shows as an IV but does not cache an IV value.
So it feels like some internal state of the interpreter is changing and affecting future calls, which would suggest a bug.
My inclination would be to single step through the sprintf implementation (Perl_sv_vcatpvfn_flags in sv.c) to see where and why behaviour changes between first and second pass; if I find a confluence of time and will I'll have a go at that, since I'm pretty familiar with that code.
Update: Oh, I tried changing the testcase to Dump($_); Dump($_+1), which takes print out of the equation: it's pp_hot.c: pp_add() that needs looking at. (Not pp.c: pp_i_add(), which should be relevant only under use integer.) And the sprintf implementation wasn't relevant anyway, since we were doing a plain print: that was just me looking for the keys under the lamppost.
Hugo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Strange behaviour when printing certain numeric values
by syphilis (Archbishop) on Jan 18, 2024 at 02:54 UTC |