la4j icon indicating copy to clipboard operation
la4j copied to clipboard

It is not nessesary to compare dobles with zero using EPS

Open vkostyukov opened this issue 11 years ago • 5 comments

It looks like we don't need to use EPS while comparing doubles with zero. So, we can rewrite all the following cases:

if (Math.abs(value) > Matrices.EPS) { // not a zero
...
}
if (Math.abs(value) < Matrices.EPS) { // zero
...
}

to

if (value != 0.0) { // not a zero
...
}
if (value == 0.0) { // zero

}

But we stiil need EPS while comapring two doubles.

vkostyukov avatar Sep 11 '13 04:09 vkostyukov

Can value != (double)0.0 and value != 0.0 give different results?

SamoylovMD avatar Sep 11 '13 06:09 SamoylovMD

I dont' think so. The javac should parse 0.0 as double literal.

vkostyukov avatar Sep 11 '13 07:09 vkostyukov

double x = Matrices.EPS / 20;
System.out.println(x == 0.0);
System.out.println(Math.abs(x) < Matrices.EPS);

gives

false
true

SamoylovMD avatar Sep 11 '13 08:09 SamoylovMD

Ok, I will move it to the next milestone. We will think about it more.

vkostyukov avatar Sep 19 '13 05:09 vkostyukov

Moving to the next milestone.

vkostyukov avatar Apr 24 '14 08:04 vkostyukov