develooper Front page | | Postings from February 2007

Re: [PATCH] signbit detection (was [perl #39875] -0.0 loses signednessupon numeric comparison)

Andy Dougherty
February 9, 2007 08:50
Re: [PATCH] signbit detection (was [perl #39875] -0.0 loses signednessupon numeric comparison)
Message ID:
On Fri, 9 Feb 2007, Andy Dougherty wrote:

> I'll send the metaconfig unit separately in a follow-up message.
Here's my proposed d_signbit.U unit.

?RCS: $Id$
?RCS: You may distribute under the terms of either the GNU General Public
?RCS: License or the Artistic License, as specified in the README file.
?MAKE:d_signbit: nvtype Compile Setvar cat run rm echo i_math i_sunmath
?MAKE:	-pick add $@ %<
?S:	This variable conditionally defines the HAS_SIGNBIT symbol, which
?S:	indicates to the C program that the signbit() routine is available
?S:	and safe to use with perl's intern NV type.
?C:	This symbol, if defined, indicates that the signbit routine is
?C:	available to check if the given number has the sign bit set.
?C:	This should include correct testing of -0.0.  This will only be set
?C:	if the signbit() routine is safe to use with the NV type used internally
?C:	in perl.  Users should call Perl_signbit(), which will be #defined to
?C:	the system's signbit() function or macro if this symbol is defined.
?H:#$d_signbit HAS_SIGNBIT		/**/
?LINT:set d_signbit d_use_signbit
: see if signbit exists
$echo $n "Checking to see if you have signbit() available to work on $nvtype... $c" >&4
$cat >try.c <<EOCP
#$i_math I_MATH
#$i_sunmath I_SUNMATH
#ifdef I_MATH
#  include <math.h>
#ifdef I_SUNMATH  /* Solaris special math library */
#  include <sunmath.h>
#define NV $nvtype
int main(int argc, char **argv)
    NV x = 0.0;
    NV y = -0.0;
    if ((signbit(x) == 0) && (signbit(y) != 0))
	return 0;
	return 1;
set try
if eval $compile; then
    if $run ./try; then
        $echo "Yes." >&4
        $echo "Signbit seems to be available, but doesn't work as I expected."
        $echo "I won't use it." >&4
    $echo "Nope." >&4
set d_signbit
eval $setvar
$rm -f try.* try

    Andy Dougherty
    Dept. of Physics
    Lafayette College, Easton PA 18042 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About