【发布时间】:2016-06-29 07:55:15
【问题描述】:
当我将** 运算符与负数BigDecimal 和十进制数BigDecimal 一起使用时,会因Zero or negative argument 错误而失败。
我检查了一些类似的值,如下所示:
-2 ** '0.3'.to_d
# => -1.23114441
2 ** '0.3'.to_d
# => 1.23114441
2 ** '0.3'.to_d
# => 1.23114441
-2 ** '0.3'.to_d
# => -1.23114441
2.to_d ** '0.3'.to_d
# => 1.23114441
-2.to_d ** '0.3'.to_d
# => Math::DomainError: Zero or negative argument for log
from (pry):111:in `**'
2.to_d ** 3.to_d
# => 8.0
-2.to_d ** 3.to_d
# => -8.0
为什么会发生此错误,我该如何解决?
【问题讨论】:
标签: ruby bigdecimal