<Swing Dev> [15] RFR JDK-8220811: SpinnerNumberModel floating point rounding issue
Alexey Ivanov
alexey.ivanov at oracle.com
Mon Feb 17 09:50:31 UTC 2020
On 13/02/2020 21:33, Sergey Bylokhov wrote:
> On 2/12/20 8:21 am, Alexey Ivanov wrote:
>> The bug report says that going from -0.15 to -0.10 does not allow
>> going back to -0.15. This happens because the result of this sequence
>> of operations cannot be represented exactly, or, in other words,
>> because of rounding errors; or rather the result is less than the set
>> minimal value.
>>
>> Can we set the value of the spinner to the set minimal value instead
>> of disallowing the operation. I mean, after going up the displayed
>> value is -0.10; going down by 0.05 gives the result which is less
>> than the minimal value for the spinner, and thus going down is not
>> allowed. What if we set the value of the spinner to its minimal value
>> instead?
>
> In this case, we will need to update all types including int. Isn't it
> will be surprised that the spinner will show the value which is not
> calculated as
> "defaultValue + stepValue * stepCount"?
>
Wouldn't a comment make the intention clear?
Otherwise there will always be cases where Spinner with float/double
behaves unexpectedly, i.e. does not allow increasing/decreasing a value
where one expects it to.
This new approach should also work for int too; although it's redundant
as integer arithmetic is precise.
--
Regards,
Alexey
More information about the swing-dev
mailing list