Re: Smarter than BigDecimal Class
- From: Patricia Shanahan <pats@xxxxxxx>
- Date: Mon, 17 Jul 2006 19:29:57 GMT
Patricia Shanahan wrote:
Luc The Perverse wrote:"Mark Space" <markspace@xxxxxxxxxxxxx> wrote in message news:85Fug.49763$VE1.29844@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxLuc 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
- References:
- Smarter than BigDecimal Class
- From: Luc The Perverse
- Re: Smarter than BigDecimal Class
- From: Mark Space
- Re: Smarter than BigDecimal Class
- From: Luc The Perverse
- Re: Smarter than BigDecimal Class
- From: Patricia Shanahan
- Smarter than BigDecimal Class
- Prev by Date: Re: namespace hierarchy best practices
- Next by Date: displaying text in jtextarea
- Previous by thread: Re: Smarter than BigDecimal Class
- Next by thread: namespace hierarchy best practices
- Index(es):
Relevant Pages
|