Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by syphilis (Chancellor)
on Feb 20, 2013 at 02:23 UTC ( #1019685=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.

He has log, but not exp.

Perhaps there's also something helpful in Math::BigFloat's _pow() sub:
# Taylor: | u u^2 u^3 | # x ** y = 1 + | --- + --- + ----- + ... | # |_ 1 1*2 1*2*3 _|
where (I gather)
u = y * ln x
Cheers,
Rob

Replies are listed 'Best First'.
Re^4: [OT] Function to do x**y for |y|<1 w/o ** operator.
by BrowserUk (Pope) on Feb 20, 2013 at 02:49 UTC

    Here's the Taylor series version, but it converges much less quickly and achieved less accuracy (at least for very small x):

    #! perl -slw use strict; our $N //= 32; sub myExp2 { my $x = shift; my( $r, $top, $bot ) = ( 1, $x, 1 ); $r += $top / $bot, $top *= $x, $bot *= $_ for 2 .. $N; $r; } printf "%30.20g : %30.20g \n", exp( $_ ), myExp2( $_ ) #, myExp2( $_ ) + - exp( $_ ) for map log( 10**$_ ), -10 .. 10; __END__ C:\test>exp -N=227 9.9999999999999965e-011 : -9.2662709999185665e-008 1.0000000000000007e-009 : -8.6393006494132869e-009 9.999999999999982e-009 : 1.1100933780704416e-008 9.9999999999999943e-008 : 9.9888569074918635e-008 1.0000000000000004e-006 : 1.0000228347576172e-006 9.9999999999999974e-006 : 1.0000001331927489e-005 0.00010000000000000009 : 0.00010000000018884082 0.0010000000000000002 : 0.0010000000000062366 0.010000000000000005 : 0.0099999999999984095 0.10000000000000002 : 0.099999999999999867 1 : 1 10.000000000000002 : 10.000000000000004 100.00000000000004 : 100 999.99999999999977 : 999.99999999999955 10000.000000000009 : 10000.000000000007 100000.00000000001 : 100000.00000000004 999999.99999999953 : 999999.99999999977 10000000.000000006 : 10000000.000000009 100000000.00000018 : 100000000.00000022 999999999.99999928 : 999999999.99999964 10000000000.000004 : 10000000000.000002

    Try going higher with the iterations and things turn to #inf.


    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019685]
help
Chatterbox?
[marto]: good morning all
[Corion]: Hi marto!
[Corion]: The fun show at $work continues, as The Big Project is now in its second week of frantic live-bugfixing and weekend releases where nobody knows what went live. Nothing has been tested anyway.
erix mutters cantankerously under his breath
Corion watches from the sidelines. Or rather, from behind, as my system only gets output from that process and my programs adhere strictly to the GIGO design principle.
[erix]: ah, that's nice to hear Corion :)
[Corion]: erix: Yeah, the sad thing is that all I can do is document things, so I can point fingers when the auditors come :-/
[Corion]: "I'm here to open tickets and point fingers. And I'm all out of tickets."
[erix]: didn't Sybase have pretty good auditing? :) (this is a vague memory)
[erix]: (culprits often are upstream of db of course)

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2017-03-28 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (328 votes). Check out past polls.