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
hex "e" misunderstood by Math::BigRat #9786
Comments
From zefram@fysh.orgCreated by zefram@fysh.org$ perl -MMath::BigRat -lwe 'print Math::BigRat->new("0x7d")' Looks like whatever's interpreting the input string sees the "e" and The error message generated varies according to which Math::BigInt backend Math::BigInt does not get confused. It handles "0x7e" correctly, Perl Info
|
From @sisyphus----- Original Message -----
This is fixed by the following patch: #################################### Inline Patch--- BigRat.pm_orig Mon Jul 6 21:08:19 2009
+++ BigRat.pm Mon Jul 6 21:22:01 2009
@@ -191,7 +191,7 @@
return $class->bnan() if $n =~ /\/\s*$/; # 1/ isn't valid
($n,$d) = split (/\//,$n);
# try as BigFloats first
- if (($n =~ /[\.eE]/) || ($d =~ /[\.eE]/))
+ if (($n =~ /[\.eE]/) || ($d =~ /[\.eE]/) && $n !~ /^0x/)
{
local $Math::BigFloat::accuracy = undef;
local $Math::BigFloat::precision = undef;
@@ -279,7 +279,7 @@
}
# simple string input
- if (($n =~ /[\.eE]/))
+ if (($n =~ /[\.eE]/ && $n !~ /^0x/))
{
# looks like a float, quacks like a float, so probably is a float
$self->{sign} = 'NaN';
All I've done is insert the "$n !~ /^0x/" condition in two places. It's the And I *haven't* checked if that patch breaks anything else :-) Cheers, |
The RT System itself - Status changed from 'new' to 'open' |
From @jimcOn Mon, Jul 6, 2009 at 7:38 AM, Sisyphus<sisyphus1@optusnet.com.au> wrote:
patch passed all current tests here, Summary of my perl5 (revision 5 version 11 subversion 0) configuration: Characteristics of this binary (from libperl): |
From jaleto@gmail.comHowdy, Since I am co-maintainer of Math::BigRat and TELS informed me that he I suggest this patch as a fix for this issue, which includes two new tests: $ git diff v0.22 Inline Patchdiff --git a/lib/Math/BigRat.pm b/lib/Math/BigRat.pm
index 6d77f98..570daef 100644
--- a/lib/Math/BigRat.pm
+++ b/lib/Math/BigRat.pm
@@ -279,7 +279,7 @@ sub new
}
# simple string input
- if (($n =~ /[\.eE]/))
+ if (($n =~ /[\.eE]/) && $n !~ /^0x/)
{
# looks like a float, quacks like a float, so probably is a float
$self->{sign} = 'NaN';
diff --git a/t/bigrat.t b/t/bigrat.t
index d898335..c7563e5 100755
--- a/t/bigrat.t
+++ b/t/bigrat.t
@@ -8,7 +8,7 @@ BEGIN
$| = 1;
chdir 't' if -d 't';
unshift @INC, '../lib'; # for running manually
- plan tests => 198;
+ plan tests => 200;
}
# basic testing of Math::BigRat
@@ -53,6 +53,8 @@ foreach my $func (qw/new bnorm/)
$x = $cr->$func('-inf'); ok ($x,'-inf');
$x = $cr->$func('1/'); ok ($x,'NaN');
+ $x = $cr->$func("0x7e"); ok($x, 126);
+
# input ala '1+1/3' isn't parsed ok yet
$x = $cr->$func('1+1/3'); ok ($x,'NaN');
I have created a "hex" topic branch to fully fix this issue. [2] PS: So I should be updating Porting/Maintainers.pl, right? Cheers, [0] http://github.com/leto/Math-BigRat/tree/master On Mon, Jul 6, 2009 at 8:18 AM, Jim Cromie<jim.cromie@gmail.com> wrote:
-- Jonathan Leto |
From @rgs2009/7/7 Jonathan Leto <jaleto@gmail.com>:
Yes. In the list of things that might be nice to do in blead (but won't be I'm not sure if there is yet a sane solution (that is, not submodules)
|
From @dcollinsnFixed in 5.12.0. -- |
@dcollinsn - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#67244 (status was 'resolved')
Searchable as RT67244$
The text was updated successfully, but these errors were encountered: