Double precision values

Just a day before joining the Google Code Jam Qualification Round. This is my first experience with such an online coding contest. It was really fun.

There were three problems, of which I was able to solve two. But for one problem, I was asked to work with values ​​that are really huge. I am a Java guy and I thought I would go to a double variable. Unfortunately, double accuracy was also not enough. Moreover, I attended this during the final stage, I did not have time to delve into it much (plus solution 1 is enough to qualify for the next stage).

My question is how to have a precision mechanism that is more than double. My coding experience is in Java, so it would be great if you could answer on that line.

thank

0
source share
3 answers

Java has BigDecimall for arbitrary precision arithmetic - but it is much slower than using double.

It is also possible that the problem in question should have been solved using algebraic transformations and, for example, working with logarithms.

+5
source

If the problem requires integers, you can use BigInteger.

Also, long is slightly better than double for integers, with 63 bits compared to 53 bits of precision (assuming positive numbers).

+2
source

, BigDecimal - , , .

+1

All Articles