RFR: 8205592: BigDecimal.doubleValue() is depressingly slow

Joe Darcy darcy at openjdk.org
Thu Apr 27 16:44:23 UTC 2023


On Wed, 26 Apr 2023 08:30:07 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:

> No, that would not be correct. It would be subject to [double rounding](https://en.wikipedia.org/wiki/Rounding#Double_rounding), against the spec.
> 
> For example, `BigDecimal` 1.000000059604644775390626 should round to `float` `1.0000001f`. When going to the closest `double` and then to the closest `float`, however, it first rounds to `double` `1.0000000596046448` and the to `float` `1.0f`.

Ah right; thanks for the correction -- since the set of possible inputs in this case isn't constrained by operations on float values, the 2p+2 property that hold for {+, -, *, /, sqrt} doesn't hold here.

> I have no objections as long as it is a 1 letter name that does not conflict with others. Have you a preferred one?

I usually use "bd" or "bi" for such BigDecima/BigInteger variables myself and use "d" for double; "v" or "w" have integer-ish feel to me so perhaps one of those?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/9410#discussion_r1179424759
PR Review Comment: https://git.openjdk.org/jdk/pull/9410#discussion_r1179432887


More information about the core-libs-dev mailing list