Hi Sergey, Pankaj, On 12/02/2020 07:59, Sergey Bylokhov wrote:

On 2/11/20 11:52 pm, Pankaj Bansal wrote:Hi Sergey,<< Sometimes there are difference:Ok, I see it now. So, should I just close this bug as not an issuewith proper comments or make changes using Math.fma for best possibleresults? The probability of issue happening will decrease usingMath.fma(b, c, a) as compared to normal a+b*c.According to the source code, the multiplication is needed only tochange the sign of the result so c is always -1 or 1, not sure is itpossible to get some rounding issues or not(need to check somehow)?

Can it be replaced with simple addition / subtraction: newValue = currentValue - step; or newValue = currentValue + step;

`On another note, we know there's always a possibility for rounding`

`errors; in addition, many decimal fractions cannot be represented`

`exactly as a binary fraction. Can we solve the problem another way then?`

`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?`

Would it work? It should.

Regards, Pankaj -----Original Message----- From: Sergey Bylokhov Sent: Wednesday, February 12, 2020 1:09 PMTo: Pankaj Bansal <pankaj.b.ban...@oracle.com>;swing-dev@openjdk.java.netSubject: Re: <Swing Dev> [15] RFR JDK-8220811: SpinnerNumberModelfloating point rounding issueI am not able to find any issue with this approach.Sometimes there are difference: double b = 0.10000000000000011;constructor [1]:0.1000000000000001165734175856414367444813251495361328125constructor [2]: 0.10000000000000012<<But it is possible to create Float.valueOf(float) and pass it tothis constructor, isn't it? this will work for any primitives.<<[3] public SpinnerNumberModel(Number value, Comparable<?> minimum, Comparable<?> maximum, Number stepSize)Yes, it is true. If we create "Float" objects from primitive floatand pass to the constructor, things work fine. But what if the useris passing the primitive float values directly? As the doubleconstructor is there, it is called instead of this constructor whichaccepts objects. This creates issue.I don’t see this in spec that users should not use primitive floatdirectly and should first create "Float" object and then createSpinnerNumberModel. So they will use primitive floats directly andrun into these issues.This is described in the top level specification of this class.As I suggested earlier, either we should remove constructors withprimitive double or add constructor for primitive float.The primitive variants are there because it was decided that"integers and doubles" are quite common, so they have specialconstructors, this is also described in the top-level spec of the class.

-- Regards, Alexey