Re: Smarter than BigDecimal Class



Patricia Shanahan wrote:
Luc The Perverse wrote:
"Mark Space" <markspace@xxxxxxxxxxxxx> wrote in message news:85Fug.49763$VE1.29844@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Luc The Perverse wrote:
So you have to be smarter than the class that you're using. Apparently I don't qualify.

So I have 3 BigIntegers and I need to divide them with high precision and then convert them to doubles (in an array) and they need to be accurate to within 1E-9.

Just curious. What application requires this kind of precision? This is far in excess of what I'd consider appropriate for scientific applications. Is this some weird kind of financial app?

Yet another top coder problem :)

It simply has to be the "right" answer, which the problem statement defines to being within 1E-9 of the "true" value (presumably they calculate it to greater precision than that. I was getting overflow when I was trying to use regular doubles (in retrospect the imprecision may have been coming from ints before they were turned to doubles, but I found it an excellent opportunity to familiarize myself with the BigDecimal class. After all - if I'm not learning anything, what is the point of doing all these practice problems? hehe)

Using BigDecimal would make sense to me if the integers are outside the
range that can be exactly converted to double. All Java int values are
in that range, but not all longs.

If the integers can be exactly converted to double, the result of doing
so, and then doing the decimal division is the closest double to the

I meant to type "and then doing the double division"

infinite precision result of dividing the integers. You can't do better
than that and end up with a double result.

Patricia
.



Relevant Pages

  • Re: Precision print doubles manipulator
    ... I've just created a stream manipulator that "precision formats" doubles. ... write doubles with up to 6 decimals: ...
    (microsoft.public.vc.language)
  • Re: Smarter than BigDecimal Class
    ... So I have 3 BigIntegers and I need to divide them with high precision and ... then convert them to doubles (in an array) and they need to be accurate ... What application requires this kind of precision? ... use regular doubles (in retrospect the imprecision may have been coming from ...
    (comp.lang.java.programmer)
  • Re: Smarter than BigDecimal Class
    ... So I have 3 BigIntegers and I need to divide them with high precision and then convert them to doubles and they need to be accurate to within 1E-9. ... It simply has to be the "right" answer, which the problem statement defines to being within 1E-9 of the "true" value (presumably they calculate it to greater precision than that. ... All Java int values are ...
    (comp.lang.java.programmer)
  • Re: long double in gcc implementations
    ... mastering a high or arbitrary precision library), ... What mingw is concerned, please note that mingw uses the ... Maybe the compiler uses long doubles internally, ... You can check this by doing long double calculations and then ...
    (comp.lang.c)
  • Re: awk command
    ... when i execute the above command it gives me all the values in the ... echo hi|awk '' ... You need more precision in your problem statement if you want ...
    (comp.unix.programmer)