问题
I have a simple calculation:
Enum.reduce(1..5, 0, &:math.pow/2)
But I get this error:
** (ArithmeticError) bad argument in arithmetic expression
(stdlib) :math.pow(5, 262144.0)
(elixir) lib/enum.ex:1478: anonymous fn/3 in Enum.reduce/3
(elixir) lib/range.ex:80: Enumerable.Range.reduce/5
(elixir) lib/enum.ex:1477: Enum.reduce/3
Is there a limitation in Elixir for arithmetic calculations?
回答1:
You're trying to calculate 5^262144
- it's such a huge number erlang bails out. Such number can't even be represented by floating point numbers - the maximal float is about 1.7e308
来源:https://stackoverflow.com/questions/38533313/elixir-arithmeticerror-bad-argument-in-arithmetic-expression