This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Promote on overflow to bigint/num, and not to NV. This is a new lexical user-pragma to use exact arithmetic without loosing precision on all builtin arithmetic ops. As in perl6. It is of course a bit slower than without. Closes #21.
- Loading branch information
Showing
17 changed files
with
306 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,30 @@ | ||
package exact_arith; | ||
our $VERSION = '0.01'; | ||
sub unimport { delete $^H{exact_arith}; } | ||
sub import { $^H{exact_arith} = 1; } | ||
|
||
1; | ||
__END__ | ||
=head1 NAME | ||
exact_arith - promote on overflow to bigint/num | ||
=head1 SYNOPSIS | ||
use exact_arith; | ||
print 18446744073709551614 * 2; # => 36893488147419103228, a bigint object | ||
{ no exact_arith; | ||
print 18446744073709551614 * 2; # => 3.68934881474191e+19 | ||
} | ||
=head1 DESCRIPTION | ||
This is a new lexical user-pragma since cperl5.24 to use exact | ||
arithmetic, without loosing precision on all builtin arithmetic ops. | ||
As in perl6. | ||
It is of course a bit slower, than without. | ||
=cut |
This file contains 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,24 @@ | ||
#!./perl -- -*- mode: cperl; cperl-indent-level: 4 -*- | ||
|
||
BEGIN { | ||
chdir 't' if -d 't'; | ||
@INC = ( '.', '../lib' ); | ||
} | ||
|
||
use strict; | ||
require '../t/test.pl'; | ||
plan(4); | ||
|
||
$|=1; | ||
|
||
use exact_arith; | ||
my $n = 18446744073709551614 * 2; # => 36893488147419103228, a bigint object | ||
is(ref $n, 'bigint'); | ||
is($n, 36893488147419103228); | ||
|
||
{ | ||
no exact_arith; | ||
my $m = 18446744073709551614 * 2; | ||
is(ref $n, ''); | ||
is($n, 3.68934881474191e+19); | ||
} |
This file contains 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 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 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.