diff options
author | Andy Dougherty <doughera@lafayette.edu> | 2007-02-09 06:40:51 -0500 |
---|---|---|
committer | H.Merijn Brand <h.m.brand@xs4all.nl> | 2007-02-10 17:22:04 +0000 |
commit | ed140128eb692ebeaa21f2775f8d3c34e9a94094 (patch) | |
tree | 1ed1e0da9af5eb071615d6d32c0bebd64980a3d3 /numeric.c | |
parent | 75c442e4b9bb8eeee80e9ac09713243f25ff6ed6 (diff) | |
download | perl-ed140128eb692ebeaa21f2775f8d3c34e9a94094.tar.gz |
signbit detection (was [perl #39875] -0.0 loses signedness upon numeric comparison)
Message-ID: <Pine.LNX.4.62.0702091121400.10202@fractal.phys.lafayette.edu>
p4raw-id: //depot/perl@30192
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -1024,6 +1024,38 @@ Perl_my_frexpl(long double x, int *e) { #endif /* +=for apidoc Perl_signbit + +Return a non-zero integer if the sign bit on an NV is set, and 0 if +it is not. + +If Configure detects this system has a signbit() that will work with +our NVs, then we just use it via the #define in perl.h. Otherwise, +fall back on this implementation. As a first pass, this gets everything +right except -0.0. Alas, catching -0.0 is the main use for this function, +so this is not too helpful yet. Still, at least we have the scaffolding +in place to support other systems, should that prove useful. + + +Configure notes: This function is called 'Perl_signbit' instead of a +plain 'signbit' because it is easy to imagine a system having a signbit() +function or macro that doesn't happen to work with our particular choice +of NVs. We shouldn't just re-#define signbit as Perl_signbit and expect +the standard system headers to be happy. Also, this is a no-context +function (no pTHX_) because Perl_signbit() is usually re-#defined in +perl.h as a simple macro call to the system's signbit(). +Users should just always call Perl_signbit(). + +=cut +*/ +#if !defined(HAS_SIGNBIT) +int +Perl_signbit(NV x) { + return (x < 0.0) ? 1 : 0; +} +#endif + +/* * Local variables: * c-indentation-style: bsd * c-basic-offset: 4 |