in reply to Re: Efficiently working with huge exponents
in thread Efficiently working with huge exponents

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:

5.19469336319992513461071316398707637029610983547139039022052215500033 +0748128713140857944929474604946407890576242141198731139214 2324060603669100591443085161671423608538064065009247433495758206421181 +6041163544936451093418528960464769157767991031321856057398 2666947442696473760475992972158927479218009273759516049811496993843563 +6416559392963943454835743787169456588299548100913424497325 0905049420519380402064586712958594039933889035337394627220130813347089 +718415056564330782186171899023705...


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

Replies are listed 'Best First'.
Re^3: Efficiently working with huge exponents
by wanna_code_perl (Friar) on Mar 21, 2015 at 13:54 UTC

    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

        Sure. I'm just playing around with some algorithmic approaches to bound some algorithmic complexities. I could have easily left things in a higher-order notation, but since it's just for fun anyway, I wanted to see how far I could push the boundaries of Perl's large number support.

        In other words, I often permit myself to get sidetracked when I'm already sidetracked for fun anyway. :-)