Skip Menu |

This queue is for tickets about the Math-BigInt CPAN distribution.

Report information
The Basics
Id: 110942
Status: resolved
Priority: 0/
Queue: Math-BigInt

People
Owner: Nobody in particular
Requestors: miyagawa [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.999717



Subject: Math::BigInt->new() now gives warnings
Date: Tue, 05 Jan 2016 23:29:49 +0000
To: bug-Math-BigInt [...] rt.cpan.org
From: Tatsuhiko Miyagawa <miyagawa [...] gmail.com>
Since 1.999712, Math::BigInt->new() gives warnings when it's given undef values or no arguments at all. Show quoted text
> perl -MMath::BigInt -e 'warn Math::BigInt->VERSION; Math::BigInt->new()'
1.999710 at -e line 1. Show quoted text
> cpanm Math::BigInt@1.999712 -n
Successfully installed Math-BigInt-1.999712 (upgraded from 1.999710) 1 distribution installed Show quoted text
> perl -MMath::BigInt -e 'warn Math::BigInt->VERSION; Math::BigInt->new()'
1.999712 at -e line 1. Use of uninitialized value in new at -e line 1
On Tue Jan 05 18:30:09 2016, miyagawa@gmail.com wrote: Show quoted text
> > Since 1.999712, Math::BigInt->new() gives warnings when it's > given undef values or no arguments at all.
The warning was introduced on purpose, since you can't have a Math::BigInt object with no value. A Math::BigInt object must be initialized to something, and the warning tells you that you have not specified this "something". The new object will be initialized to zero, though, as before: $ perl -MMath::BigInt -wle 'print "x = ", Math::BigInt -> new()' Use of uninitialized value in new at -e line 1 x = 0 but if you want a zero, the right way to do it is with bzero() or new(0). I can't see why this warning is a problem, but if you can explain to me when or why this warning might be a problem, I will consider removing it.
Subject: Re: [rt.cpan.org #110942] Math::BigInt->new() now gives warnings
Date: Wed, 06 Jan 2016 16:05:46 +0000
To: bug-Math-BigInt [...] rt.cpan.org
From: Tatsuhiko Miyagawa <miyagawa [...] gmail.com>
OK, understood, except that the code was called in some other perl module, Math::BaseConvert and as a user I cannot stop the warnings. It means that we should just patch the module though. https://metacpan.org/source/CHROMATIC/Math-BaseConvert-1.7/lib/Math/BaseConvert.pm#L48 On Tue, Jan 5, 2016 at 11:46 PM Peter John Acklam via RT < bug-Math-BigInt@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=110942 > > > On Tue Jan 05 18:30:09 2016, miyagawa@gmail.com wrote:
> > > > Since 1.999712, Math::BigInt->new() gives warnings when it's > > given undef values or no arguments at all.
> > The warning was introduced on purpose, since you can't have a Math::BigInt > object with no value. A Math::BigInt object must be initialized to > something, and the warning tells you that you have not specified this > "something". > > The new object will be initialized to zero, though, as before: > > $ perl -MMath::BigInt -wle 'print "x = ", Math::BigInt -> new()' > Use of uninitialized value in new at -e line 1 > x = 0 > > but if you want a zero, the right way to do it is with bzero() or new(0). > > I can't see why this warning is a problem, but if you can explain to me > when or why this warning might be a problem, I will consider removing it. >
This is related: Old code: $ perl -MMath::BigInt -E 'say Math::BigInt::blcm(); say Math::BigInt::bgcd()' 0 0 New: $ perl -MMath::BigInt -E 'say Math::BigInt::blcm(); say Math::BigInt::bgcd()' Use of uninitialized value in new at -e line 1. 0 Use of uninitialized value in new at -e line 1. 0 I think gcd and lcm with an empty list should work without warning, but I can see an argument otherwise. However this warning is confusing. The code is relying on the old behavior. (1) if the new(undef) warning goes away, this problem goes away. (2) totally untested and unofficial change to the start of the function: my $y = shift || 0; my($x); (3) Add before that line the totally untested and unofficial change: return $class->bzero() unless @_; (4) similar to the above but basically doing the same as the old code did with that: return $class->new(0) unless @_;
On Wed Jan 06 11:06:06 2016, miyagawa@gmail.com wrote: Show quoted text
> OK, understood, except that the code was called in some other perl > module, Math::BaseConvert and as a user I cannot stop the warnings.
Hm. That is unfortunate, but on the other hand, that's what might happen when people don't read the documentation. For more than 12(!) years, since Math-BigInt-1.67, released in December 2003, the documentation has stated: Currently, Math::BigInt::new() defaults to 0, while Math::BigInt::new('') results in 'NaN'. This might change in the future, so use always the following explicit forms to get a zero or NaN: $zero = Math::BigInt->bzero(); $nan = Math::BigInt->bnan(); Perhaps I should change the warning to something like Using new() or new("") is deprecated.
On Fri Jan 08 17:54:57 2016, DANAJ wrote: Show quoted text
> I think gcd and lcm with an empty list should work without warning, (...)
I agree. At the same time I would like to discourange using blcm() and bgcd() as functions. At the very least, they should be used class methods. I am also annoyed by the fact that they don't modify their object, which is inconsistent with the rest of the interface, but I'm not sure this can be done without causing more harm than good.
On Fri Jan 08 17:54:57 2016, DANAJ wrote: Show quoted text
> This is related: > > Old code: > > $ perl -MMath::BigInt -E 'say Math::BigInt::blcm(); say > Math::BigInt::bgcd()' > 0 > 0 > > New: > > $ perl -MMath::BigInt -E 'say Math::BigInt::blcm(); say > Math::BigInt::bgcd()' > Use of uninitialized value in new at -e line 1. > 0 > Use of uninitialized value in new at -e line 1. > 0 > > I think gcd and lcm with an empty list should work without warning.
I have looked further into this. I am not sure what bgcd() and blcm() with no argument should return. Currently they return zero, but to me that seems like an arbitrary choice. I checked with Octave and Wolfram Alpha. The former requires at least two input arguments. The latter requires at least one. Does it make sense at all that bgcd() and blcm() return zero? Could you, or someone else, show me a case where this result is useful?
Fixed in v1.999717