Elixir: (ArithmeticError) bad argument in arithmetic expression

十年热恋 提交于 2019-12-12 03:15:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!