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

Re: PATCH: srand returns the seed

Thread Previous | Thread Next
From:
Andy Dougherty
Date:
August 3, 2010 06:26
Subject:
Re: PATCH: srand returns the seed
Message ID:
alpine.DEB.2.00.1008030832100.19379@fractal.phys.lafayette.edu
On Mon, 2 Aug 2010, Bo Lindbergh wrote:

> Nicholas Clark wrote:
> > What I can't work out is whether there is any shortcut way in ANSI C to find
> > out whether a value is -0, distinct from 0, short of *printf().
> 
> As long as the compiler is sufficiently C99-like:
> 
>     fpclassify(value)==FP_ZERO && signbit(value)

Yes, both copysign() and signbit() are widely available.  The challenge 
arises in that perl tries to rely only on C89-like behavior, since not all 
compilers support the C99 standard.  To help provide appropriate warnings 
to developers who use gcc, we often add -ansi to gcc's flags, which 
effectively hides things like signbit().

In ANSI C, if signbit() isn't available, the only other thing I can think 
of doing is to assume IEEE-754 and explicitly check the correct bit some 
way or another.  

-- 
    Andrew Dougherty		doughera@lafayette.edu

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