kennethgoodman / rockstar_math

mathlib for rockstar language
2 stars 2 forks source link

Power function only works with integer exponents #7

Closed DavideFauri closed 6 years ago

DavideFauri commented 6 years ago

As the title says, the source code for the Power(number, exponent) function seems to work only with integer exponents.

> from rockmath import Power
> Power(2,3)
8
> Power(2,3.5)
16
> 2**3.5
11.313708498984761

At the moment I'm trying to research the best way to do it, probably with some mathematical trick involving logarithms and exponentiation. In the meanwhile, could you put it in the todolist?

kennethgoodman commented 6 years ago

How about?

e^x = base^exponent
=> x = exponent * ln( base)
base^exponent = e^(exponent * ln( base))

This is still a floating point exponent but it may get us closer.

Easier problem to solve

DavideFauri commented 6 years ago

Yes, that is probably the way to do it.

This would mean to re-write the Exp function so it does not call the Power function, but I can again use Taylor series approximation.

I have a PR ready for that, give me a moment :)

kennethgoodman commented 6 years ago

Believe we can close this issue.