1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-22 22:28:02 +01:00

WRaster: Changed equality/inequality comparison on floating point number

The equality comparison (a == b) is known to be a dangerous trap
when floating-point arithmetics are involved. This patch changes
all the cases which try to do this to a safer check.
This commit is contained in:
Christophe CURIS
2013-05-11 00:07:16 +02:00
committed by Carlos R. Mafra
parent 80a59696e5
commit 8ef38e9910
3 changed files with 31 additions and 6 deletions

View File

@@ -187,8 +187,20 @@ static double B_spline_filter(double t) /* box (*) box (*) box (*) box */
static double sinc(double x)
{
/*
* The original code did this:
* if (x != 0) ...
* This code is unsafe, it should be:
* if (fabs(x) > EPSILON) ...
*
* But the call to fabs is already done in the *ONLY* function
* that call sinc: 'Lanczos3_filter'
*
* The goal was to avoid a Divide-by-0 error, now we also
* avoid a +/-inf result too
*/
x *= PI;
if (x != 0)
if (x > 1.0E-9)
return (sin(x) / x);
return (1.0);
}