<changes>
<release version="3.7-beta4" date="2010-??-??">
+ <action dev="poi-developers" type="fix">50033 - Improved rounding in MOD</action>
<action dev="poi-developers" type="add">Generate SHA1 hashes of distribution files, alongside existing MD5 ones</action>
</release>
<release version="3.7-beta3" date="2010-09-24">
package org.apache.poi.hssf.record.formula.functions;
+
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
* This class is an extension to the standard math library
result = Double.NaN;
}
else if (sign(n) == sign(d)) {
- double t = Math.abs(n / d);
- t = t - (long) t;
- result = sign(d) * Math.abs(t * d);
+ result = n % d;
}
else {
- double t = Math.abs(n / d);
- t = t - (long) t;
- t = Math.ceil(t) - t;
- result = sign(d) * Math.abs(t * d);
+ result = ((n % d) + d) % d;
}
return result;
}
-
/**
* inverse hyperbolic cosine
* @param d
}
public void testMod() {
+
+ //example from Excel help
+ assertEquals(1.0, MathX.mod(3, 2));
+ assertEquals(1.0, MathX.mod(-3, 2));
+ assertEquals(-1.0, MathX.mod(3, -2));
+ assertEquals(-1.0, MathX.mod(-3, -2));
+
+ assertEquals((double) 1.4, MathX.mod(3.4, 2));
+ assertEquals((double) -1.4, MathX.mod(-3.4, -2));
+ assertEquals((double) 0.6000000000000001, MathX.mod(-3.4, 2.0));// should actually be 0.6
+ assertEquals((double) -0.6000000000000001, MathX.mod(3.4, -2.0));// should actually be -0.6
+
+ // Bugzilla 50033
+ assertEquals(1.0, MathX.mod(13, 12));
}
public void testNChooseK() {