develooper Front page | perl.vmsperl | Postings from June 2002

Re: [PATCH #2] Re: [PATCH] numeric.c:S_mulexp10 -- quit when youcan

Thread Previous | Thread Next
Craig A. Berry
June 18, 2002 22:39
Re: [PATCH #2] Re: [PATCH] numeric.c:S_mulexp10 -- quit when youcan
Message ID:
At 10:55 PM -0500 6/7/02, Craig A. Berry wrote:
>So the following gets us to do the fake underflow as well as fake
>overflow in the absence of IEEE math:
>--- numeric.c;-1	Fri Jun  7 16:40:25 2002
>+++ numeric.c	Fri Jun  7 22:18:01 2002
>@@ -744,9 +744,8 @@
>      * [1] Trying to establish a condition handler to trap floating point
>      *     exceptions is not a good idea. */
> #if defined(VMS) && !defined(__IEEE_FP) && defined(NV_MAX_10_EXP)
>-    if (!negative &&
>-        (log10(value) + exponent) >= (NV_MAX_10_EXP))
>-        return NV_MAX;
>+    if ((log10(value) + exponent) >= (NV_MAX_10_EXP))
>+        return negative ? 0.0 : NV_MAX;
> #endif
>     /* In UNICOS and in certain Cray models (such as T90) there is no
>[end of patch]

Urk.  I found a case where this isn't right (or actually
lib/Math/Trig.t found a case where it isn't right):

$ perl -e "my $x = 100.00000000000000001; print $x;"

so far so good, but now add another zero after the decimal:

$ perl -e "my $x = 100.000000000000000001; print $x;"

In the second example we are definitely hitting the code that returns
zero if the exponent is too small.  This only happens with a D_FLOAT
configuration, where NV_MAX_10_EXP will be 38.  The other values are:

NUMERIC\S_mulexp10\value:       0.100000000000000E+21
NUMERIC\S_mulexp10\exponent:    18
NUMERIC\S_mulexp10\negative:    1

This is all a bit silly since there aren't 21 digits of precision in
a double, but there is also apparently nothing to keep it from
attempting to represent more digits than it actually can and it
shouldn't print 0 when the right answer is 100.  It's past my bedtime
and I don't understand Perl_my_atof well enough to do anything about
this just yet.
Craig A. Berry

"... getting out of a sonnet is much more
 difficult than getting in."
                 Brad Leithauser

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About