0

Why does Erlang not include arbitrary precision for math functions? I recently had to use math:pow(2,4333), and it throws an error. Why does Erlang not use libraries like GMP? Are there any plans to include it in the standard library? (Haskell uses it, [strike]even Java has bignums[strike]).

Thanks.

Update: To add more perspective, I understand that it can be done using NIFs. I was solving problems from hackerrank in which the input uses larger numbers. pow/2 can be easily written in Erlang and it worked, but for larger computations, it would be slow.
Java returns double for pow so it does not work for Math.pow(2, 1024) which gives Infinity.

1 Answers1

6

Erlang has bignums for integers but uses 64-bit IEEE standard floating point numbers. So while you can happily compute factorial(10000) with integers by default the math library uses floating point so math:pow(2, 4333) does not work.

rvirding
  • 20,848
  • 2
  • 37
  • 56
  • 4
    `crypto` module uses integers and defines `crypto:mod_pow/3` which you can use instead of `math:pow/2` if it fits your needs. – Paul Guyot Nov 11 '13 at 06:14
  • this answer doesn't answer the question, like at all. – Tommy Mar 03 '16 at 18:04
  • Because it wasn't deemed interesting for most uses of Erlang. If you want to do serious numerical calculation you would call a suitable package from Erlang. – rvirding Mar 04 '16 at 15:51