[erlang-questions] math:pow(X, Y).
Mon Mar 19 18:29:49 CET 2012
In general the math library is for float arithmetic, just like in C. My
guess is that the time when this was written, there was no bignum support.
There's an implementation of an int_pow/2 function in mochinum (currently
part of mochiweb):
Not the fastest algorithm on the planet, but much better than the naive
O(N) implementation. There might be better libraries out there with faster
algorithms or maybe a GMP library, but my needs were pretty minimal so I
wrote the few functions I needed.
1> mochinum:int_pow(42, 909).
On Mon, Mar 19, 2012 at 10:17 AM, Yves S. Garret <yoursurrogategod@REDACTED
> Hi all,
> That's the standard method that I use to raise a value to a power. I
> compared this to the way Python does raising to a power and this is the
> result that I get:
> 11> math:pow(42, 909).
> ** exception error: bad argument in an arithmetic expression
> in function math:pow/2
> called as math:pow(42,909)
> Now. Why is it in Erlang's case I get a float as a return value? Is
> there a method that only returns a long? Or do most erlang coders have a
> custom power function if they want ridiculously large numbers?
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions