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

I never tried it before but Math::BigInt can be used to see these numbers in full precision.

use strict; use warnings; use Math::BigInt; my $x = Math::BigInt->new('0x1fffffffffffff'); $x->blsft(1023 - 52); print '0x1fffffffffffff: ' . $x->bstr() . "\n\n"; my $y = Math::BigInt->new('0x1ffffffffffffe'); $y->blsft(1023 - 52); print '0x1ffffffffffffe: ' . $y->bstr() . "\n\n"; my $z = $x - $y; print 'difference : ' . $z->bstr() . "\n\n"; my $n = Math::BigInt->new(2); $n->bpow(971); print '2**971 : ' . $n->bstr() . "\n\n"; print "length of largest double precision value in base 10 + : " . length($x->bstr()) . " digits\n"; print "length of 2**971 (least significant bit of mantissa) in base 10 + : " . length($n->bstr()) . " digits\n"; __END__ 0x1fffffffffffff: 1797693134862315708145274237317043567980705675258449 +965989174768031572607800285387605895586327668781715404589535143824642 +343213268894641827684675467035375169860499105765512820762454900903893 +289440758685084551339423045832369032229481658085593321233482747978262 +04144723168738177180919299881250404026184124858368 0x1ffffffffffffe: 1797693134862315508561243283845062402343434371574593 +359244048724485818457545561143884706399431262203219608040271573715708 +098528849645117430440876627676009095943319277282370788761887605795325 +637686986540648252621157710157914639830148577040081234194593862451417 +23703148097529108423358883457665451722744025579520 difference : 1995840309534719811656372713036838566067451260435457 +541502547242437211891868964065784957965492635701089342446844192495243 +972437988393593660739171798284831420320005672951085676517537721444362 +987182653356744543923993330810455120870388888855268448044157507120906 +8757560416423584952303440099278848 2**971 : 1995840309534719811656372713036838566067451260435457 +541502547242437211891868964065784957965492635701089342446844192495243 +972437988393593660739171798284831420320005672951085676517537721444362 +987182653356744543923993330810455120870388888855268448044157507120906 +8757560416423584952303440099278848 length of largest double precision value in base 10 : 309 +digits length of 2**971 (least significant bit of mantissa) in base 10 : 293 +digits

Replies are listed 'Best First'.
Re^5: Large floating point literals
by BrowserUk (Patriarch) on May 21, 2009 at 01:21 UTC

    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.