develooper Front page | perl.perl5.porters | Postings from December 2016

[perl #130423] DBL_MAX (and the like) not parsed

Thread Next
Jarkko Hietaniemi
December 28, 2016 14:48
[perl #130423] DBL_MAX (and the like) not parsed
Message ID:
# New Ticket Created by  Jarkko Hietaniemi 
# Please include the string:  [perl #130423]
# in the subject line of all future correspondence about this issue. 
# <URL: >

Problem: Perl doesn't parse the decimal expansion of DBL_MAX at all.

The example code shows to different wrong ways, and one correct
result.  (Apologies for the bad wrapping, plain email is not
the best format for long lines or code, see the attachments.)

$x1 = 
$y1 = sprintf("%f", $x1);
$y2 = sprintf("%f", eval 
chomp(my $e2 = $@);
$y3 = sprintf("%f", DBL_MAX);
print "y1 = $y1\n";
print "y2 = $y2 ($e2)\n";
print "y3 = $y3\n";

Output (from the 5.25.6 I have installed, but blead is no different):

y1 = Inf
y2 = 0.000000 (Number too long at (eval 3) line 1.)
y3 = 

You can remove the eval wrapping from $y2 to get the parse to die 

The above form of DBL_MAX is the IEEE 754 double precision (64-bit)
maximum.  There can be others: the 80-bit x86-style "uselongdouble"
maximum (LDBL_MAX) or the 128-bit IEEE-754 quadruple precision
(which may or may not be "uselongdouble", it may be the native
format/format chosen with the C compiler).

Both of these formats would require close to 5000 decimal digits in the
full expansion, having such a large statically allocated token buffer
would probably not be the best idea.  (There is even octuple precision
defined in the IEEE-754, though I haven't heard of implementations.)

[Note: I tried sending this earlier, but I think my local outgoing mail
queue is not really outgoing]

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