简体   繁体   English

双精度值

[英]Double precision values

Just a day before I participated in the qualification round of Google Code Jam. 就在我参加Google Code Jam资格考试的前一天。 This is my first experience of such an online coding contest. 这是我第一次参加这种在线编码竞赛。 It was really fun. 这真的很有趣。

There were three problems given of which i was able to solve two. 给出了三个问题,我能够解决两个问题。 But on one of the problems I was asked to work with values that are really huge. 但是,在其中一个问题上,我被要求使用非常巨大的价值观。 I am a Java guy and I thought I would go for double variable. 我是一个Java专家,我认为我会追求双变量。 Unfortunately, the precision of double also was not enough. 不幸的是,双精度还不够。 Moreover, I attended this during the closing stage, I was not having the time to dig much into it (plus solving 1 is enough to qualify to the next stage). 而且,我在结束阶段参加了此会议,但我没有时间去深入研究它(加上解决方案1足以进入下一阶段)。

My question is this, How to have a precision mechanism that is greater than double. 我的问题是,如何拥有大于两倍的精度机制。 My coding experience is in Java, so it would be great if you could please answer in that lines. 我的编码经验是Java,所以如果您能在那一行中回答,那将是很棒的。

Thanks 谢谢

Java has BigDecimal l for arbitrary-precision arithmetic - but it's much, much slower than using double . Java具有用于任意精度算术的BigDecimal l-但是它比使用double慢得多。

It's also possible that the problem in question was supposed to be soved by using algebraic transformations and eg work with logarithms. 也有可能应该通过使用代数变换来解决问题,例如使用对数。

If the problem requires integers you can use BigInteger. 如果问题需要整数,则可以使用BigInteger。

Also, long is slightly better than double for integers, with 63 bits compared to 53 bits of precision (assuming positive numbers). 同样,对于整数,long略好于double,具有63位,而对于53位精度(假定为正数),则为long。

您可以使用任意精度的数字,例如BigDecimal-速度较慢,但​​可以指定的精度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM