-
Notifications
You must be signed in to change notification settings - Fork 601
fix sv_numeq and add other SV numeric comparison APIs #23966
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
Draft
tonycoz
wants to merge
11
commits into
Perl:blead
Choose a base branch
from
tonycoz:23918-cmp-api
base: blead
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
26d01a1
add sv_numne() to the API
tonycoz d65f56a
sv.c: extract the common parts of sv_numeq_flags and sv_numne_flags
tonycoz c28118d
sv_numeq/sv_numne: consolidate the similar documentation
tonycoz b1dca3f
add sv_numcmp() to the API
tonycoz 6325643
sv_num*: correctly handle "0+" overloaded values
tonycoz 3dfca8b
add sv_numle(), sv_numlt(), sv_numge(), sv_numgt() APIs
tonycoz 8a82284
sv_numcmp_common: only call magic once if the SVs are the same
tonycoz 628202f
add tests for void context calls to overloads
tonycoz 2ff5a79
amagic_call: accept a AMGf_force_scalar flag to force scalar context
tonycoz 6b31a64
pp_multiconcat: use the new AMGf_force_scalar
tonycoz 096a2ec
add perldelta for sv_numeq fix and other sv_num* additions
tonycoz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ use strict; | |
| use warnings; | ||
| use Carp; | ||
|
|
||
| our $VERSION = '1.47'; | ||
| our $VERSION = '1.48'; | ||
|
|
||
| require XSLoader; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #!perl | ||
|
|
||
| use Test::More tests => 24; | ||
| use XS::APItest; | ||
| use Config; | ||
| use strict; | ||
|
|
||
| my $four = 4; | ||
| is sv_numcmp($four, 4), 0, '$four == 4'; | ||
| is sv_numcmp($four, 5), -1, '$four < 5'; | ||
|
|
||
| is sv_numcmp(5, $four), 1, '5 > $four'; | ||
|
|
||
| SKIP: | ||
| { | ||
| $Config{d_double_has_nan} | ||
| or skip "No NAN", 2; | ||
| my $nan = 0+"NaN"; | ||
| is sv_numcmp($nan, 0), 2, '$nan not comparable'; | ||
| is sv_numcmp($nan, $nan), 2, '$nan not comparable even with itself'; | ||
| } | ||
|
|
||
| my $six_point_five = 6.5; # an exact float, so == is fine | ||
| is sv_numcmp($six_point_five, 6.5), 0, '$six_point_five == 6.5'; | ||
| is sv_numcmp($six_point_five, 6.6), -1, '$six_point_five < 6.6'; | ||
|
|
||
| # NULLs | ||
| is sv_numcmp(undef, 1), -1, "NULL sv1"; | ||
| is sv_numcmp(1, undef), 1, "NULL sv2"; | ||
|
|
||
| # GMAGIC | ||
| "10" =~ m/(\d+)/; | ||
| is sv_numcmp_flags($1, 10, 0), -1, 'sv_numcmp_flags with no flags does not GETMAGIC'; | ||
| is sv_numcmp_flags($1, 10, SV_GMAGIC), 0, 'sv_numecmp_flags with SV_GMAGIC does'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo |
||
|
|
||
| # overloading | ||
| { | ||
| package AlwaysTen { | ||
| use overload | ||
| '<=>' => sub { | ||
| return $_[2] ? $_[1] <=> 10 : 10 <=> $_[1] | ||
| }, | ||
| '0+' => sub { 123456 }; | ||
| } | ||
| my $obj = bless([], "AlwaysTen"); | ||
|
|
||
| is sv_numcmp($obj, 10), 0, 'AlwaysTen is 10'; | ||
| is sv_numcmp($obj, 11), -1, 'AlwaysTen is not 11'; | ||
| is sv_numcmp(10, $obj), 0, 'AlwaysTen is 10 on the right'; | ||
| is sv_numcmp(11, $obj), 1, 'AlwaysTen is not 11 on the right'; | ||
|
|
||
| SKIP: | ||
| { | ||
| $Config{d_double_has_nan} | ||
| or skip "No NAN", 1; | ||
| my $nan = 0+"NaN"; | ||
|
|
||
| is sv_numcmp($obj, $nan), 2, 'AlwaysTen vs $nan is not comparable'; | ||
| } | ||
|
|
||
| is sv_numcmp_flags($obj, 10, SV_SKIP_OVERLOAD), 1, | ||
| 'AlwaysTen is not 10 with SV_SKIP_OVERLOAD'; | ||
| } | ||
|
|
||
| # +0 overloading with large numbers and using fallback | ||
| { | ||
| my $big = ~0; | ||
| my $bigm1 = $big-1; | ||
| package MyBigNum { | ||
| use overload "0+" => sub { $_[0][0] }, | ||
| fallback => 1; | ||
| } | ||
| my $o1 = bless [ $big ], "MyBigNum"; | ||
| my $o2 = bless [ $big ], "MyBigNum"; | ||
| my $o3 = bless [ $bigm1 ], "MyBigNum"; | ||
|
|
||
| is $o1 <=> $o2, 0, "perl op gets it right"; | ||
| is $o1 <=> $bigm1, 1, "perl op still gets it right for left overload"; | ||
| is $o1 <=> $o3, 1, "perl op still gets it right for different values"; | ||
| is sv_numcmp($o1, $o2), 0, "sv_numcmp two overloads"; | ||
| is sv_numcmp($o1, $o3), 1, "sv_numcmp two different overloads"; | ||
| is sv_numcmp($o1, $big), 0, "sv_numcmp left overload"; | ||
| is sv_numcmp($bigm1, $o3), 0, "sv_numcmp right overload"; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have
builtin::nannow ;)(repeated variously throughout the test files)