[numbers/general] unlikely argument type warning

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[numbers/general] unlikely argument type warning

Eric Barnhill
For the line:

Assert.assertFalse(zero.equals(Double.valueOf(0)));

Eclipse is producing a warning:

"Unlikely argument type for equals(): Double seems to be unrelated to
Fraction"

Does anyone have a suggestion for how to handle this warning, thank you.

Eric
Reply | Threaded
Open this post in threaded view
|

Re: [numbers/general] unlikely argument type warning

Gilles Sadowski
On Thu, 13 Dec 2018 11:39:05 -0800, Eric Barnhill wrote:
> For the line:
>
> Assert.assertFalse(zero.equals(Double.valueOf(0)));

What is it testing?
Conceptually, I'd expect "assertTrue" (zero as a fraction
is equal to zero as a double).

>
> Eclipse is producing a warning:
>
> "Unlikely argument type for equals(): Double seems to be unrelated to
> Fraction"
>
> Does anyone have a suggestion for how to handle this warning, thank
> you.

Perhaps Eclipse indicates that the test is useless (since
"Double" is not a subclass of "Fraction").

And perhaps "Fraction" should overload "equals":

public boolean equals(double x, int ulp) {
    return Precision.equals(doubleValue(), x, ulp);
}
public boolean equals(Number x, int ulp) {
    return equals(x.doubleValue, ulp);
}
public boolean equals(double x) {
    return equals(doubleValue(), x, 1);
}

Gilles

>
> Eric


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]