<Swing Dev> [15] RFR JDK-8220811: SpinnerNumberModel floating point rounding issue
Sergey Bylokhov
Sergey.Bylokhov at oracle.com
Mon Feb 17 10:10:06 UTC 2020
On 2/17/20 1:50 am, Alexey Ivanov wrote:
> 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.
But what value is expected/unexpected? If the programmer wants to use float arithmetic and allow the user to select some value in the diapason by the JSpinner, is it expected that spinner return values which are exactly duplicate simple steps of float addition or not?
> This new approach should also work for int too; although it's redundant as integer arithmetic is precise.
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?
--
Best regards, Sergey.
More information about the swing-dev
mailing list