Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: [OT] Function to do x**y for |y|<1 w/o ** operator.

by BrowserUk (Pope)
on Feb 19, 2013 at 20:08 UTC ( #1019656=note: print w/ replies, xml ) Need Help??


in reply to Re^2: [OT] Function to do x**y for |y|<1 w/o ** operator.
in thread [OT] Function to do x**y for |y|<1 w/o ** operator.

Update:Changed constants for slightly greater accuracy for the sake of another couple of iterations.

Here's a somewhat more accurate, and much faster version:

#! perl -slw use strict; sub myExp{ my $e = 1 + ( shift() / 4294967296 ); $e *= $e for 1 .. 32; $e; } printf "%30.20g : %30.20g\n", exp( $_ ), myExp( $_ ) for map log( 10**$_ ), -10 .. 10; __END__ C:\test>exp 9.9999999999999965e-011 : 1.0000000285332257e-010 1.0000000000000007e-009 : 1.0000000829163549e-009 9.999999999999982e-009 : 1.0000002130576865e-008 9.9999999999999943e-008 : 9.9999976329917627e-008 1.0000000000000004e-006 : 9.9999969112813618e-007 9.9999999999999974e-006 : 9.9999977582604716e-006 0.00010000000000000009 : 9.999998681099902e-005 0.0010000000000000002 : 0.00099999984556405617 0.010000000000000005 : 0.0099999993405499293 0.10000000000000002 : 0.099999996702749588 1 : 1 10.000000000000002 : 9.9999952742988558 100.00000000000004 : 100.00000084944983 999.99999999999977 : 999.99959325720954 10000.000000000009 : 10000.000169889967 100000.00000000001 : 99999.966690555739 999999.99999999953 : 1000000.1401405634 10000000.000000006 : 9999996.1589527112 100000000.00000018 : 100000003.39779937 999999999.99999928 : 999999662.81900096 10000000000.000004 : 10000002874.419859

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".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re^3: [OT] Function to do x**y for |y|<1 w/o ** operator.
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019656]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (11)
As of 2015-07-29 18:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (267 votes), past polls