in reply to Re: Determining whether a value is zero.
in thread Determining whether a value is zero.

It may be pointless from the sense of practical application. I found it interesting as a way of familiarizing the various representations of zero, and how the various operators treat a scalar (dual-)variable in Perl.

  • Comment on Re^2: Determining whether a value is zero.

Replies are listed 'Best First'.
Re^3: Determining whether a value is zero.
by BrowserUk (Patriarch) on Mar 10, 2011 at 13:51 UTC

    I'm not adverse to a purely intellectual challenge.

    But the specification of what is and what is not zero doesn't seem to comply with any either real-world or rational definition that I can think of. I cannot think of any existing implementation that would interprete "0" as zero, and not "00" or "0 ". Nor can I see any rational for doing so.

    Without some logic as to why these arbitrary rules have been picked, you might as well do:

    #! perl -slw use strict; use feature qw[ state ]; use Scalar::Util qw[ dualvar ]; my @true = ( 0, "0", 0.0, Scalar::Util::dualvar( 0, 1 ) ); my @false = ( 1, "foo", "00", "0 ", undef, "", Scalar::Util::dualvar( 1, 0 ), "0.0" ); sub isZero { state %isZero; unless( %isZero ) { $isZero{ $_ } = 1 for @true; $isZero{ $_ } = 0 for @false; } return $isZero{ $_ } if exists $isZero{ $_ }; die "Don't know"; } print "$_ : ", isZero( $_ ) for @true; print "$_ : ", isZero( $_ ) for @false;

    As it can be infinitely extended to deal with any set of illogical rules.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Without some logic as to why these arbitrary rules have been picked,
      Ok, here's the other part of the challenge: what's the logic about what for some people seem to be "arbitrary" or even "illogical"?