in reply to Efficiently working with huge exponents

2**1024000

Are all your big numbers powers of 2?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
  • Comment on Re: Efficiently working with huge exponents

Replies are listed 'Best First'.
Re^2: Efficiently working with huge exponents
by BrowserUk (Patriarch) on Mar 21, 2015 at 13:00 UTC

    The point I was getting at is that 2**1024000, is already logarithmic. Ie. 1024000 is log2 of your number.

    Thus, to convert it to log10(), you only need divide it by log2( 10 ).

    Then all you need is:

    sub log2{ log( $_[0] ) / log( 2 ) } sub log2ToLog10{ $_[0] / log2( 10 ) } print log2ToLog10( 1024000 );; 308254.715559917

    And once you have that, displaying it in human readable form becomes:

    my $log10 = log2ToLog10( 1024000 ); printf "%.16fe%d\n", 10**( $log10 - int( $log10 )), int( $log10 );; 5.1946933632179482e308254

    Which is pretty accurate according to wolfram/alpha:


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    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". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

      A good observation and valid question, but, no, my calculations are not all powers of 2. Thanks for the math reminder. :-)

        Can I ask how you are arriving at these huge numbers in your program?


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        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". I'm with torvalds on this
        In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked