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

Merged
merged 1 commit into from
Jun 12, 2024

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
@jkeenan jkeenan removed the defer-next-dev This PR should not be merged yet, but await the next development cycle label Jun 10, 2024
@jkeenan
Copy link
Contributor

jkeenan commented Jun 10, 2024

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

Since blead is now open, I'll take this ticket for the purpose of merging it in 2 or 3 days. So if anyone has a new objection, please speak up! Thanks.

@jkeenan jkeenan self-assigned this Jun 10, 2024
@jkeenan jkeenan merged commit 7c85ab5 into Perl:blead Jun 12, 2024
30 checks passed
@t-a-k t-a-k deleted the sv_2nv-IV_MIN branch June 15, 2024 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants