Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Math Groovy在处理非常大的数字时抛出Numberformatexception_Math_Groovy_Numberformatexception_Bignum - Fatal编程技术网

Math Groovy在处理非常大的数字时抛出Numberformatexception

Math Groovy在处理非常大的数字时抛出Numberformatexception,math,groovy,numberformatexception,bignum,Math,Groovy,Numberformatexception,Bignum,因此,在Intellij IDEA中使用groovy,我使用以下代码得到一个异常: def t = (100000G**100000000000G) Math.pow(self.doubleValue(), exponent.doubleValue()) 现在我意识到这些数字是任何一个理智的人都不想计算的,但出于提问的目的,出于我的好奇心,为什么这会抛出以下例外 Exception in thread "main" java.lang.NumberFormatException at jav

因此,在Intellij IDEA中使用groovy,我使用以下代码得到一个异常:

def t = (100000G**100000000000G)
Math.pow(self.doubleValue(), exponent.doubleValue())
现在我意识到这些数字是任何一个理智的人都不想计算的,但出于提问的目的,出于我的好奇心,为什么这会抛出以下例外

Exception in thread "main" java.lang.NumberFormatException
at java.math.BigDecimal.<init>(BigDecimal.java:494)
at java.math.BigDecimal.<init>(BigDecimal.java:383)
at java.math.BigDecimal.<init>(BigDecimal.java:806)
at java.math.BigDecimal.valueOf(BigDecimal.java:1274)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.power(DefaultGroovyMethods.java:14303)
at org.codehaus.groovy.runtime.dgm$489.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
at dev.folling.code.Main.main(Main.groovy:11)
线程“main”java.lang.NumberFormatException中的异常 在java.math.BigDecimal.(BigDecimal.java:494) 在java.math.BigDecimal.(BigDecimal.java:383) 在java.math.BigDecimal.(BigDecimal.java:806) 位于java.math.BigDecimal.valueOf(BigDecimal.java:1274) 位于org.codehaus.groovy.runtime.DefaultGroovyMethods.power(DefaultGroovyMethods.java:14303) 位于org.codehaus.groovy.runtime.dgm$489.invoke(未知源) 位于org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$pojoMetamethodSiteNounwrapnocerc.invoke(PojoMetaMethodSite.java:274) 位于org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56) 位于org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) 位于org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) 位于org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128) 位于dev.folling.code.Main.Main(Main.groovy:11) 将
**
替换为
.power()
不会改变它的任何内容。
该错误显然是由于某个点出现非法字符造成的。我认为这可能是内存错误,但我不确定。

您可以尝试为代码创建一个断点,并尝试深入研究它

这就是引擎盖下会发生的事情

public static BigInteger power(BigInteger self, BigInteger exponent) {
    return exponent.signum() >= 0 && exponent.compareTo(BI_INT_MAX) <= 0?self.pow(exponent.intValue()):BigDecimal.valueOf(Math.pow(self.doubleValue(), exponent.doubleValue())).toBigInteger();
}
然后BigDecimal将使用valueof将其转换为BigInteger

BigDecimal.valueOf("Infinity")
这就是为什么您会得到一个NumberFormatException

比尔


Tim

您可以尝试为代码创建一个断点,并尝试深入研究它

这就是引擎盖下会发生的事情

public static BigInteger power(BigInteger self, BigInteger exponent) {
    return exponent.signum() >= 0 && exponent.compareTo(BI_INT_MAX) <= 0?self.pow(exponent.intValue()):BigDecimal.valueOf(Math.pow(self.doubleValue(), exponent.doubleValue())).toBigInteger();
}
然后BigDecimal将使用valueof将其转换为BigInteger

BigDecimal.valueOf("Infinity")
这就是为什么您会得到一个NumberFormatException

比尔


Tim

有趣,虽然我预料到了,但我不知道大整数/大小数有“无穷”有趣,而我预料到了,我不知道大整数/大小数有“无穷”有趣