develooper Front page | perl.perl5.porters | Postings from April 2004

Re: [perl #28538] Math::BigInt doesn't grok "0 but true"

Thread Previous | Thread Next
From:
Tels
Date:
April 14, 2004 14:59
Subject:
Re: [perl #28538] Math::BigInt doesn't grok "0 but true"
Message ID:
200404142252.42291@bloodgate.com
-----BEGIN PGP SIGNED MESSAGE-----

Moin,

On Wednesday 14 April 2004 22:20, Tassilo von Parseval wrote:
> On 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
> converting it to a number (it's 0 both times). The difference is that "0
> but true" wont ever trigger a warning. This is intentional and you will
> find this special case by grepping through the perl source.

*sigh* another of these "special" cases in Perl. How should BigInt handle 
this? I think it should be NaN. 

Other modules have similiar "problems":

te@null:~> perl -MMath::GMP -le 'print Math::GMP->new("0 but true") + 1'
1
te@null:~> perl -MMath::GMP -le 'print Math::GMP->new("0 but true") + 2'
2
te@null:~> perl -MMath::GMP -le 'print Math::GMP->new("0but true") + 2'
2
te@null:~> perl -MMath::GMP -le 'print Math::GMP->new("01but true") + 2'
2
te@null:~> perl -MMath::GMP -le 'print Math::GMP->new("01but 3true") + 2'
2
te@null:~> perl -MMath::GMP -le 'print Math::GMP->new("NaN") + 2'
2
te@null:~> perl -MMath::GMP -le 'print Math::GMP->new("1") + 2'
3

Whatever BigInt should do, the current behaviour is quite old:

# perl -IMath-BigInt-0.01/lib/ -MMath::BigInt -lwe 'print 
$Math::BigInt::VERSION'
0.01
# perl -IMath-BigInt-0.01/lib/ -MMath::BigInt -lwe 'print 
Math::BigInt->new("0 but true")+9'
NaN

> That's what dualvars usually do. A variable has such a split personality
> whenever
>
>     $var+0 ne $var;
>
> Whether you give priority to the numerical or the string slot is a
> semantic issue. Since Math::BigInt->new takes a string as argument,
> using the string slot would seem more plausible. Whichever way you do
> it, it should be documented.

Ok. I prefer the string version, too. 

(While that might cause problems with libraries that are confused by 
dual-vars I think it can be worked around).

Cheers,

Tels

- -- 
 Signed on Wed Apr 14 22:44:54 2004 with key 0x93B84C15.
 Visit my photo gallery at http://bloodgate.com/photos/
 PGP key on http://bloodgate.com/tels.asc or per email.

 "Die deutsche Zensoren  - - - - - - - - - - - - - - - - - - - - - - - - -
 - - - - - - - - - - - - - - - - - - - - - - - - - - Dummköpfe - - - - - -
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 - - - - - - - - - - - -." Heinrich Heine

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)
Comment: When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl.

iQEVAwUBQH2kiXcLPEOTuEwVAQEZPwf/U7GHLA9URj+fAtRBpKFgfDGbMDczqq+x
ZSOvASwwnhsjncneaxHNbdqW08sMELPhkh3lLRTwElHQh9cSB4xuuIZ97c/NSmNq
uQrYocrxHLKTc6CvTxculdN6q+kavez01GaF6KSAwpK5xOKJzFtt1TImiqrEmgTy
ncABH+fVBNSB6FY12Mqt3XxM/ZzasqTCG6c47wKMSC6z8NUlWJG58oDOXs9JN4VJ
JUgPKpSMXvvpdPOpLYcjhFi0xQVlRDvNLwqZn19V9JTZrgsbq0Em7HQabAMKT2UI
7nsdQ08mtrmovEffM81RAZKSdNMX+ut5yyo8z7jF8Ymc+Qf7fEcfxw==
=mLug
-----END PGP SIGNATURE-----


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About