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

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

Thread Previous | Thread Next
From:
Jan Dubois
Date:
August 2, 2010 11:01
Subject:
RE: [perl #76756] PATCH: srand returns the seed
Message ID:
037001cb326c$a1fc62c0$e5f52840$@activestate.com
On Thu, 29 Jul 2010, Andy Dougherty wrote:
> On Wed, 28 Jul 2010, Jan Dubois wrote:
> 
> > 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.
> 
> Even in floating point, 0 is special.  When you know what you are doing,
> comparing for exactly 0 is both reasonable and reliable.

Yes, but -0 is typically not an explicit integral value, but the result
of an arithmetic underflow, followed by rounding the small negative number
(that cannot be represented with the current precision) to 0.  The sign
is only kept to indicate if you approached zero from above or from below.

As such you are relying on the fact that your operation actually underflows
and produces an exact -0 instead of a very small negative number.  This
depends very much on the actual representation of the floating point number,
as well as the current rounding mode, and is generally not a portable and
reliable assumption.

Cheers,
-Jan



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