...
 
Commits (2)
......@@ -21,6 +21,12 @@ public class NumericUtils {
*/
public final static double TAU = Math.PI * 2; // radians in full circle
/**
* Cutoff parameter for arctan function, don't fit phase below this value
*/
public static final double ATAN_CUTOFF = 1e-40;
public static final ThreadLocal<DecimalFormat> DECIMAL_FORMAT =
ThreadLocal.withInitial(() -> {
DecimalFormat format = new DecimalFormat("#.###");
......@@ -162,10 +168,8 @@ public class NumericUtils {
// Setting this to a very small number to avoid jumps in phase response (e.g. RandomizedExperiment)
// when the complex number is small.
// However, atan2 is discontinuous at 0, so we do not want that to be a possible input
final double CUTOFF = 1e-25;
if (c.abs() < CUTOFF) {
if (c.abs() < ATAN_CUTOFF) {
return 0.;
}
......
package asl.utils;
import static asl.utils.NumericUtils.ATAN_CUTOFF;
import static asl.utils.NumericUtils.atanc;
import static asl.utils.NumericUtils.getComplexSDev;
import static asl.utils.NumericUtils.multipointMovingAverage;
......@@ -32,7 +33,7 @@ public class NumericUtilsTest {
double second = i / Math.pow(10, i);
Complex c = new Complex(first, second);
if (c.abs() > 1e-25) {
if (c.abs() > ATAN_CUTOFF) {
checkedBelowCutoff = true;
assertEquals(Math.atan2(first, second), atanc(c), 0.);
} else {
......