Updated divideTime(t1, t2) to use limits in case of t2 == 0
diff --git a/plugins/org.eclipse.app4mc.amalthea.model/src/org/eclipse/app4mc/amalthea/model/AmaltheaServices.java b/plugins/org.eclipse.app4mc.amalthea.model/src/org/eclipse/app4mc/amalthea/model/AmaltheaServices.java
index 32cc399..9fe88d7 100644
--- a/plugins/org.eclipse.app4mc.amalthea.model/src/org/eclipse/app4mc/amalthea/model/AmaltheaServices.java
+++ b/plugins/org.eclipse.app4mc.amalthea.model/src/org/eclipse/app4mc/amalthea/model/AmaltheaServices.java
@@ -416,15 +416,40 @@
return applyToTimes(BigInteger::subtract, t1, t2);
}
+ /**
+ * Divides t1 by t2
+ * <p>
+ * In case of t2 == 0 the limit t2 -> 0 is used
+ * @param t1
+ * @param t2
+ * @return t1 / t2
+ */
public static double divideTime(final @NonNull Time t1, final @NonNull Time t2) {
checkTimeArgument(t1);
checkTimeArgument(t2);
- double v1 = convertToPicoSeconds(t1).doubleValue();
- double v2 = convertToPicoSeconds(t2).doubleValue();
+ final BigInteger i1 = convertToPicoSeconds(t1);
+ final BigInteger i2 = convertToPicoSeconds(t2);
- boolean divisorIsZero = Double.compare(v2, 0d) == 0;
- return divisorIsZero ? Double.POSITIVE_INFINITY : v1 / v2;
+ if (BigInteger.ZERO.equals(i1)) {
+ if (BigInteger.ZERO.equals(i2)) {
+ // use limit: as x approaches 0 of x/x = 1
+ return 1.0;
+ } else {
+ return 0.0;
+ }
+ }
+
+ if (BigInteger.ZERO.equals(i2)) {
+ // use limit: as x approaches 0 of i1/x
+ if (i1.signum() == 1) {
+ return Double.POSITIVE_INFINITY;
+ } else {
+ return Double.NEGATIVE_INFINITY;
+ }
+ }
+
+ return i1.doubleValue() / i2.doubleValue();
}
public static @NonNull Time multiply(final @NonNull Time t1, long value) {