Hi Sergey,

<< Sometimes there are difference:
Ok, I see it now. So, should I just close this bug as not an issue with proper 
comments or make changes using Math.fma for best possible results? The 
probability of issue happening will decrease using Math.fma(b, c, a) as 
compared to normal a+b*c.

Regards,
Pankaj

-----Original Message-----
From: Sergey Bylokhov 
Sent: Wednesday, February 12, 2020 1:09 PM
To: Pankaj Bansal <pankaj.b.ban...@oracle.com>; swing-dev@openjdk.java.net
Subject: Re: <Swing Dev> [15] RFR JDK-8220811: SpinnerNumberModel floating 
point rounding issue

> I am not able to find any issue with this approach.
Sometimes there are difference:

double b = 0.10000000000000011;

constructor [1]: 0.1000000000000001165734175856414367444813251495361328125
constructor [2]: 0.10000000000000012

> <<But it is possible to create Float.valueOf(float) and pass it to this 
> 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 float and pass 
> to the constructor, things work fine. But what if the user is passing the 
> primitive float values directly? As the double constructor is there, it is 
> called instead of this constructor which accepts objects. This creates issue.
> I don’t see this in spec that users should not use primitive float directly 
> and should first create "Float" object and then create SpinnerNumberModel. So 
> they will use primitive floats directly and run into these issues.

This is described in the top level specification of this class.

> As I suggested earlier, either we should remove constructors with primitive 
> 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 special constructors, this is also 
described in the top-level spec of the class.

-- 
Best regards, Sergey.

Reply via email to