develooper Front page | perl.perl5.porters | Postings from June 2019

[perl #134230] Numifying a 0x string evaluates the hex number

Thread Previous
From:
sisyphus@cpan.org via RT
Date:
June 28, 2019 03:32
Subject:
[perl #134230] Numifying a 0x string evaluates the hex number
Message ID:
rt-4.0.24-20590-1561692752-1433.134230-15-0@perl.org
On Thu, 27 Jun 2019 18:14:38 -0700, sisyphus359@gmail.com wrote:
.....
> Is this a behaviour that should be changed ?
....

Seems to me that it's maybe a bit silly to be handing hex *integer* strings to strtod() when perl assigns hex integer barewords to IV.

It's ok when the value fits in both the IV and the NV, but when IV-precision exceeds NV-precision we can get results that don't DWIM all that well:

C:\> perl -le "print 'wtf' if 0xfffffffffffffff == '0xfffffffffffffc0' + 0;"
wtf

(That's on perl-5.30.0, ivsize and nvsize both == 8.)

It might make better sense if, in such cases, the hex integer string was handed over to srtol/strtoll.
However, strtol("023", NULL, 0) would return the decimal value 19 (same value as the perl bareword 023), but perl has always numified '023' as the decimal value 23, so there's some awkwardness there that would need to be considered.

Cheers,
Rob
 

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=134230

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About