# New Ticket Created by Jarkko Hietaniemi # Please include the string: [perl #130423] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org/Ticket/Display.html?id=130423 > 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 = '179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000'; $y1 = sprintf("%f", $x1); $y2 = sprintf("%f", eval '179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000'); chomp(my $e2 = $@); use POSIX 'DBL_MAX'; $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 = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 You can remove the eval wrapping from $y2 to get the parse to die immediately. 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