Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stringified IV_MIN sometimes unintentionally treated as NV #22171

Open
wants to merge 1 commit into
base: blead
Choose a base branch
from

Conversation

t-a-k
Copy link
Contributor

@t-a-k t-a-k commented Apr 24, 2024

String representation of IV_MIN ("-9223372036854775808" in typical 64bit build) is expected to be treated as IV in numeric context, but current perl sometimes treat it as NV.

In !NV_PRESERVES_UV case (e.g. IV and NV are both 64-bit, as in typical x86_64 build), if such string is once referred in NV context (with sv_2nv_flags()), it will be unexpectedly treated as NV in subsequent numeric references:

$ perl -wle 'my $x = my $y = "-9223372036854775808"; my $z = $x + 1.23; print $x + 0; print $y + 0'
-9.22337203685478e+18
-9223372036854775808
$

This change will hopefully resolve this.

For !NV_PRESERVES_UV case (e.g. IV and NV are both 64-bit, as in
typical x86_64 build), sv_2nv_flags() used to cache only NV for
stringified IV_MIN ("-9223372036854775808" in such case).
This leads such string to be treated as (possibly unintentionally
rounded) NV in subsequent references:

	$ perl -wle 'my $x = my $y = "-9223372036854775808";
	my $z = $x + 1.23; print $x + 0; print $y + 0'
        -9.22337203685478e+18
	-9223372036854775808
	$

This change avoid this by not treating IV_MIN specially,
with new macros added in b9b8c7d.

t/op/numconvert.t: Added tests for this.
Copy link
Contributor

@leonerd leonerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but too late for 5.40. We'll pop it in for 5.41 when we reopen

@leonerd leonerd added the defer-next-dev This PR should not be merged yet, but await the next development cycle label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defer-next-dev This PR should not be merged yet, but await the next development cycle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants