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...
|
|---|
| 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 | |
by BrowserUk (Patriarch) on Mar 21, 2015 at 20:24 UTC | |
by wanna_code_perl (Friar) on Mar 22, 2015 at 13:17 UTC |