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
Math::BigInt doesn't grok "0 but true" #7232
Comments
From zefram@fysh.orgCreated by zefram@fysh.org$ perl -MMath::BigInt -we 'print Math::BigInt->new("0"), "\n"' Similar and probably related: $ perl -MScalar::Util=dualvar -MMath::BigInt -we 'print Math::BigInt->new(dualvar(3, "foo")), "\n"' Looks like Math::BigInt is examining the string value for validity Workaround for this problem involves avoiding implicit (unguarded) Perl Info
|
From perl_dummy@bloodgate.com-----BEGIN PGP SIGNED MESSAGE----- Moin, Zefram wrote:
The doc from Math::BigInt states: Input I am responsible for the wording. What the wording means (and what I always te@null:~> perl -wle 'print "0 but true" + 2' However, I am amazed that "0 but true" is somehow "special": te@null:~> perl -wle 'print "01 but true" + 2' (That just shows my lack of understanding of Perl internals and many nooks
<$ perl -MScalar::Util=dualvar -MMath::BigInt -we 'print
Actually, BigInt checks the string value and then just hands the variable to te@null:~> perl -MScalar::Util=dualvar -MMath::BigInt=lib,GMP -we 'print While I agree these should be probably consistent, I really don't know how I mean, if the variable represents "3" and "foo" at the same time, how is One could also create an object that stringifies to something different than
Just to clarify, do you mean workaround in your code, or in BigInt? Thanx for your report, I would like to have some more info and input from Best wishes, Tels - -- "We have problems like this all of the time," Kirk said, trying to -----BEGIN PGP SIGNATURE----- iQEVAwUBQH2BY3cLPEOTuEwVAQGYsgf+M7FOr9MQBxn8i/mhkRiONsK4+eCILs7w |
The RT System itself - Status changed from 'new' to 'open' |
From tassilo.parseval@post.rwth-aachen.deOn Wed, Apr 14, 2004 at 08:22:19PM +0200 Tels wrote:
"0 but true" is no different from, say, "0 and true" when it comes to
That's what dualvars usually do. A variable has such a split personality $var+0 ne $var; Whether you give priority to the numerical or the string slot is a Tassilo |
From @hvdsTassilo von Parseval <tassilo.parseval@post.rwth-aachen.de> wrote: It isn't quite as simple as that: I wouldn't call "00" a dualvar, even Perhaps C< $var + 0 != "$var" + 0 > would be an adequate test? The canonical example of dualvars is of course $!. For Math::BigInt, if it is worth checking for such things at all, it Hugo |
From perl_dummy@bloodgate.com-----BEGIN PGP SIGNED MESSAGE----- Moin, On Wednesday 14 April 2004 22:20, Tassilo von Parseval wrote:
*sigh* another of these "special" cases in Perl. How should BigInt handle Other modules have similiar "problems": te@null:~> perl -MMath::GMP -le 'print Math::GMP->new("0 but true") + 1' Whatever BigInt should do, the current behaviour is quite old: # perl -IMath-BigInt-0.01/lib/ -MMath::BigInt -lwe 'print
Ok. I prefer the string version, too. (While that might cause problems with libraries that are confused by Cheers, Tels - -- "Die deutsche Zensoren - - - - - - - - - - - - - - - - - - - - - - - - - -----BEGIN PGP SIGNATURE----- iQEVAwUBQH2kiXcLPEOTuEwVAQEZPwf/U7GHLA9URj+fAtRBpKFgfDGbMDczqq+x |
From zefram@fysh.orgIncidentally, this bug is a duplicate of #28493. I screwed up in sending Tels via RT wrote:
If you're treating it as a string -- which you are for validity testing
This is exactly the same issue. If you want to be able to use a value as both a string and a number and $value = "$value"; or $value = 0 + $value; depending on which slot you want to take, to collapse it to an ordinary
I meant in my code. I had code that added together ordinary Perl I can see why a string-based BigInt constructor is necessary, but (a) -zefram |
From tassilo.parseval@post.rwth-aachen.deOn Wed, Apr 14, 2004 at 10:00:25PM +0100 hv@crypt.org wrote:
You are right. It's trickier than that.
That suffers from the same problem: ethan@ethan:~$ perl -MScalar::Util=dualvar The problem seems to be that a string often enough evaluates to 0 when
Which leads to the question what a reliable pure-Perl way of discovering Tassilo |
From zefram@fysh.orgHugo van der Sanden via RT wrote:
I'd say that that *is* a dualvar, just one that's unlikely to be But we shouldn't need to ask whether something is a dualvar. It should -zefram |
From @demerphq
Doesnt that make virtually every string a dualvar? Yves |
From @JohnPeacockOrton, Yves wrote:
Not unless the string has been used in a numeric context before:
John -- |
From @demerphq
I meant WRT Zefram's definition: 0+$val ne $val Which means that 0+"HHGTTG" ne "HHGTTG" thus pretty much any string that matches \D (insert suitable handwaving Basically I was making this point as an addendum to Hugo saying that the Yves |
From @JohnPeacockOrton, Yves wrote:
Doh, yes of course you were. The actual definition should be symbolically more IV != (IV*)PV where that cast stands in for the actual conversion of slots involved. John -- |
From zefram@fysh.orgI still maintain that this discussion of identifying dualvars is use warnings; sub classify($) { Try passing it the arguments 123 This function classifies scalars based on whether they could have The test that I earlier endorsed as testing for dualvarness is in Side discovery: Data::Dumper doesn't handle dualvars. It should probably -zefram |
From @HugmeirOn Thu Apr 15 09:51:36 2004, zefram@fysh.org wrote:
Looks like the discussion on this ticket petered out some years ago; As (Tangentially related, Data::Dumper still doesn't understand dualvars. |
From @cpansproutOn Sun Apr 29 10:13:39 2012, Hugmeir wrote:
But that alone would bring up many false positives. I wouldn’t consider $x a dualvar after ‘$x = "3.0"; 0+$x’. -- Father Chrysostomos |
From @doyOn Sun, Apr 29, 2012 at 11:01:25AM -0700, Father Chrysostomos via RT wrote:
I think that just not looking at the p variants would fix that issue - -doy |
From @cpansproutOn Sun Apr 29 11:27:06 2012, doy@tozt.net wrote:
Not so. $ perl5.15.9 -e '$x = "3.0"; 0+$x; use Devel::Peek; Dump $x' -- Father Chrysostomos |
From @HugmeirOn Sun, Apr 29, 2012 at 4:29 PM, Father Chrysostomos via RT <
Oh, my bad then. Guess that in the end you would have to check if the |
Migrated from rt.perl.org#28538 (status was 'open')
Searchable as RT28538$
The text was updated successfully, but these errors were encountered: