Deprecate Double.MIN_VALUE?
Louis Wasserman
lowasser at google.com
Tue Dec 3 00:11:13 UTC 2024
I think in our internal review, we've been nervous about the ambiguity of
whether MAX_NEGATIVE_VALUE has the smallest nonzero absolute value, or the
largest finite absolute value. Forcing users to negate sidesteps the issue.
On Mon, Dec 2, 2024 at 3:25 PM Archie Cobbs <archie.cobbs at gmail.com> wrote:
> Having been bitten by this bug myself, I would vote yes on this one.
>
> For symmetry's sake, I would think there should be four new constants -
> for {MIN,MAX}_{POSITIVE,NEGATIVE}_VALUE - and that both of {MIN,MAX}_VALUE
> should be deprecated.
>
> -Archie
>
> On Mon, Dec 2, 2024 at 5:18 PM Éamonn McManus <emcmanus at google.com> wrote:
>
>> At Google, we've had several issues over the years relating to
>> Double.MIN_VALUE. People have not unreasonably supposed that
>> Double.MIN_VALUE has the same relationship to Double.MAX_VALUE as
>> Integer.MIN_VALUE has to Integer.MAX_VALUE. So they think that
>> Double.MIN_VALUE is the (finite) negative number of largest magnitude,
>> rather than the positive number of smallest magnitude. We're currently
>> thinking of adding a constant MIN_POSITIVE_VALUE to Guava's Doubles
>> <https://guava.dev/releases/snapshot-jre/api/docs/com/google/common/primitives/Doubles.html> class
>> and having static analysis that suggests using that instead of
>> Double.MIN_VALUE, if that is indeed what you meant, or of course using
>> -Double.MAX_VALUE if *that* is what you meant.
>>
>> A few JDK and JavaFX bugs show that Google engineers are not the only
>> ones to be confused by this:
>> https://bugs.openjdk.org/browse/JDK-4218647
>> https://bugs.openjdk.org/browse/JDK-8092698
>> https://bugs.openjdk.org/browse/JDK-8156186
>>
>> So we also wonder if it would make sense to deprecate Double.MIN_VALUE
>> itself and introduce Double.MIN_POSITIVE_VALUE with the same meaning.
>> Obviously the same thing would apply to Float.
>>
>
>
> --
> Archie L. Cobbs
>
--
Louis Wasserman (he/they)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20241202/e6c36cb5/attachment-0001.htm>
More information about the core-libs-dev
mailing list