develooper Front page | perl.perl5.porters | Postings from July 2010

Re: [perl #76756] PATCH: srand returns the seed

Thread Previous | Thread Next
From:
Chas. Owens
Date:
July 28, 2010 12:58
Subject:
Re: [perl #76756] PATCH: srand returns the seed
Message ID:
AANLkTimE8D94K5TPThbEG3GYEjpEFaB5d1em44LPW6uO@mail.gmail.com
On Wed, Jul 28, 2010 at 15:40, Jan Dubois <jand@activestate.com> wrote:
> On Wed, 28 Jul 2010, Zefram wrote:
>> Jan Dubois wrote:
>> >Well, you _could_ add a special case to the string comparison:
>>
>> That would be a mess.  The better solution is for negative zero to
>> stringify as "0".
>
> Indeed.
>
> <not-really-serious>
>  Or add a pragma to tree "-0" as false in boolean context:
>
>    use feature "minus_zero_is_false";
>    print "Yes" if "-0";
>
>  would then not print anything.
> </not-really-serious>
>
> I'm more and more convinced that using a floating point number in
> boolean context is simply something you should not be doing for
> similar reasons that you generally are not comparing floating point
> numbers for equality.
>
> Cheers,
> -Jan
>
>

Yeah, there are definitely problems with testing floats for truthiness:

perl -MO=Deparse -e 'print "doesn't print" unless .1 * 4 - .1 * 3 - .1'

perl -MO=Deparse -e 'print "prints" unless .1 - .1'

I should probably mention that in the "Truth and Falsehood" section of
perlsyn as well.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

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