Rational number exponented to a rational number

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Rational number exponented to a rational number

Post by Ambush Commander »

pow(), bcpow() and gmp_pow() all have a restriction in that the exponent must be an integer. However, I have the need to calculate 5.66 to the 3.44 power to an arbitrary precision. How can I do this in PHP?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Re: Rational number exponented to a rational number

Post by Ambush Commander »

Ok, my mistake: pow() can do the calculation for decimal exponents.

But are there any arbitrary precision functions that can do this?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Rational number exponented to a rational number

Post by Christopher »

I confirmed that you are right. Do it manually with a loop? Ugh...
(#10850)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Re: Rational number exponented to a rational number

Post by Ambush Commander »

Well, I'm sure there's an algorithm for it, but implementing it in PHP would probably be very slow.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Re: Rational number exponented to a rational number

Post by Ambush Commander »

Anyone?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Rational number exponented to a rational number

Post by Chris Corbyn »

My only suggestions was going to be bcpow(), but according to the user comments it does not support decimal powers. I suspect that's your options exhausted, far from a custom (and more than likely slow) implementation.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Re: Rational number exponented to a rational number

Post by Oren »

arborint wrote:I confirmed that you are right. Do it manually with a loop? Ugh...
No, don't! Unless you are working with very small numbers.
The built in functions probably use algorithms much faster than whatever you can come up with.
Post Reply