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:
Tassilo von Parseval
Date:
April 14, 2004 23:49
Subject:
Re: [perl #28538] Math::BigInt doesn't grok "0 but true"
Message ID:
20040415063647.GA328@ethan
On Wed, Apr 14, 2004 at 10:00:25PM +0100 hv@crypt.org wrote:
> Tassilo von Parseval <tassilo.parseval@post.rwth-aachen.de> wrote:
> :That's what dualvars usually do. A variable has such a split personality
> :whenever
> :
> :    $var+0 ne $var;
> 
> It isn't quite as simple as that: I wouldn't call "00" a dualvar, even
> though it satisfies the above inequality.

You are right. It's trickier than that.

> Perhaps C< $var + 0 != "$var" + 0 > would be an adequate test?

That suffers from the same problem:

    ethan@ethan:~$ perl -MScalar::Util=dualvar
    $a = dualvar(0, "string");
    print $a + 0 == "$a" + 0;
    __END__
    1

The problem seems to be that a string often enough evaluates to 0 when
used in numerical context.

> The canonical example of dualvars is of course $!.
> 
> For Math::BigInt, if it is worth checking for such things at all, it
> would probably make most sense to prefer the numeric value. However,
> care needs to be taken not to end up getting perl's default coercion
> for some number to big for it to represent - that would rather defeat
> the point. However, default coercions never create a dualvar, so as
> long as there is a reliable (and efficient) way to check for them,
> no ambiguity should arise.

Which leads to the question what a reliable pure-Perl way of discovering
the dualvarness of a variable is. One probably needs to branch into XS
to do that and so there maybe should be a Scalar::Util::isdualvar()?

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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