You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Eric Barnhill <er...@gmail.com> on 2018/12/13 19:39:05 UTC

[numbers/general] unlikely argument type warning

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

Re: [numbers/general] unlikely argument type warning

Posted by Gilles <gi...@harfang.homelinux.org>.
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: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org