I would like to better understand Perl's ability and limitations processing floating point numbers. Does anyone have suggestions for my reading list?
I believe 1.79769313486232e+308 is the largest IEEE-754 double precision floating point number. Perl (32 bit on CentOS on Intel based system) can store this value in a scalar and print it but does not accept it as a numeric literal.
use strict; use warnings; use Devel::Peek; my $foo = pack("H16", "FFFFFFFFFFFFEF7F" ); Dump($foo); my $bar = unpack("d", $foo); Dump($bar); my $x = $bar; Dump($x); my $y = 1.79769313486232e+308; Dump($y); __END__ SV = PV(0x99490a0) at 0x995b760 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x9956ba8 "\377\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 SV = NV(0x99832d8) at 0x995b7b0 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486232e+308 SV = NV(0x99832d0) at 0x995b740 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486232e+308 SV = NV(0x99832e0) at 0x9968360 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = inf
As you can see from the above example, pack and unpack can be used to get this maximal value into a scalar and this value can be assigned from one scalar to another but using this value as a literal results in 'inf' instead of the expected value.
Any comments on why this is so?
update: The value of the largest IEEE-754 double precision floating point number, expressed as a base 10 integer is:
1797693134862315708145274237317043567980705675258449965989174768031572 +607800285387605895586327668781715404589535143824642343213268894641827 +684675467035375169860499105765512820762454900903893289440758685084551 +339423045832369032229481658085593321233482747978262041447231687381771 +80919299881250404026184124858368
The precision of an IEEE-754 double precision floating point value is approximately 16 decimal digits. Therefore, many numeric literals will be converted to this maximal value, including 1.7976931348623157e+308
When this maximal value is interpolated into a string, it is rounded to 15 digits of precision and the value it is rounded up to, when used as a numeric literal, is converted to inf rather than back to the maximum value. This value is: 1.79769313486232e+308.
In reply to Large floating point literals by ig
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |