<Swing Dev> [15] RFR JDK-8220811: SpinnerNumberModel floating point rounding issue

Alexey Ivanov alexey.ivanov at oracle.com
Mon Feb 17 10:56:21 UTC 2020


On 17/02/2020 10:35, Sergey Bylokhov wrote:
> On 2/17/20 2:25 am, Alexey Ivanov wrote:
>>> As far as I understand your approach, is to select the minimum if 
>>> the resulted float value after the calculation is a little bit 
>>> smaller than the minimum.
>>>
>>> So if the minimum is -0.15 and resulted value is (-0.10d - 0.05d) = 
>>> (-0.15000000000000002), what value should be shown by the spinner?
>>> the same logic for int:
>>>       the minimum is -15 and resulted value is (-11 - 5) = -16, what 
>>> value should be shown by the spinner?
>>>
>> The set minimum value: -0.15d and -15 correspondingly.
>
> That will contradicts the spec of 
> SpinnerNumberModel.getNextValue/getPreviousValue which states that 
> "@returns value - stepSize, or
> null if the sum is less than minimum."

Then it's not an option. (Unless we change the spec.)
In this case, the only thing we can do is what is already proposed. Right?

-- 
Regards,
Alexey


More information about the swing-dev mailing list