in reply to Re: Large floating point literals
in thread Large floating point literals

Thanks!! I had, foolishly, not considered that the displayed base 10 might be rounded.

Several literals slightly larger than 1.797693134862314e+308 are converted to non-infinite numbers, including two in the following test that are converted to what I believe is the largest possible value.

use strict; use warnings; use Devel::Peek; foreach my $x ( [ '1.797693134862314e+308' , 1.797693134862314e+308 ], [ '1.7976931348623141e+308' , 1.7976931348623141e+308 ], [ '1.7976931348623142e+308' , 1.7976931348623142e+308 ], [ '1.7976931348623143e+308' , 1.7976931348623143e+308 ], [ '1.7976931348623144e+308' , 1.7976931348623144e+308 ], [ '1.7976931348623145e+308' , 1.7976931348623145e+308 ], [ '1.7976931348623146e+308' , 1.7976931348623146e+308 ], [ '1.7976931348623147e+308' , 1.7976931348623147e+308 ], [ '1.7976931348623148e+308' , 1.7976931348623148e+308 ], [ '1.7976931348623149e+308' , 1.7976931348623149e+308 ], [ '1.7976931348623150e+308' , 1.7976931348623150e+308 ], [ '1.7976931348623151e+308' , 1.7976931348623151e+308 ], [ '1.7976931348623152e+308' , 1.7976931348623152e+308 ], [ '1.7976931348623153e+308' , 1.7976931348623153e+308 ], [ '1.7976931348623154e+308' , 1.7976931348623154e+308 ], [ '1.7976931348623155e+308' , 1.7976931348623155e+308 ], [ '1.7976931348623156e+308' , 1.7976931348623156e+308 ], [ '1.7976931348623157e+308' , 1.7976931348623157e+308 ], [ '1.7976931348623158e+308' , 1.7976931348623158e+308 ], [ '1.7976931348623159e+308' , 1.7976931348623159e+308 ], ) { my ($string, $number) = @$x; print "$string\n"; Dump($number); my $foo = pack('d', $number); Dump($foo); print "\n"; } __END__ 1.797693134862314e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486231e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\366\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623141e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486231e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\367\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623142e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486231e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\367\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623143e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486231e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\370\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623144e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486231e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\370\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623145e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486231e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\371\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623146e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486231e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\372\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623147e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486231e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\372\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623148e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486231e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\373\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623149e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486231e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\373\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623150e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486232e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\374\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623151e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486232e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\374\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623152e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486232e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\375\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623153e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486232e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\375\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623154e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486232e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\376\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623155e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486232e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\376\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623156e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486232e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\377\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623157e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 1.79769313486232e+308 SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\377\377\377\377\377\377\357\177"\0 CUR = 8 LEN = 12 1.7976931348623158e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = inf SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\0\0\0\0\0\0\360\177"\0 CUR = 8 LEN = 12 1.7976931348623159e+308 SV = NV(0x88c58c8) at 0x88f0b50 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = inf SV = PV(0x88ed958) at 0x88f0bc0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x88a7308 "\0\0\0\0\0\0\360\177"\0 CUR = 8 LEN = 12

Replies are listed 'Best First'.
Re^3: Large floating point literals
by BrowserUk (Patriarch) on May 20, 2009 at 23:22 UTC

    Indeed. You are correct. I chose the wrong reference:

    printf "%.20g\n", unpack 'd', scalar reverse pack 'NN', 0x7fefffff, 0x +ffffffff;; 1.7976931348623157e+308 printf "%.20g\n", unpack 'd', scalar reverse pack 'NN', 0x7fffffff, 0x +ffffffff;; 1.#QNAN printf "%.20g\n", unpack 'd', scalar reverse pack 'NN', 0xffefffff, 0x +ffffffff;; -1.7976931348623157e+308 printf "%.20g\n", unpack 'd', scalar reverse pack 'NN', 0xffffffff, 0x +ffffffff;; -1.#QNAN

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

        It's cool if you need the precision and can live with the performance of infinite precision--which is generally abysmal.

        But don't forget that on modern x86 and x64 hardware, the FPU uses 80-bit floats internally even when the calling code is using 64-bit floats. That greatly reduces the loss of precision of intermediate calculations provided that the math libraries are well written. Ie. They don't move intermediate values out of the FPU to ram and back again.

        How effective Perl's math routines are at keeping intermediate values in the FPU registers I have no idea.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.