Enhance simulation performance and accuracy by optimizing physical amount calculations and refining arithmetic operations

This commit is contained in:
Kirill
2026-10-01 20:30:53 +03:00
parent befb377774
commit f51eea6c0f
14 changed files with 155 additions and 55 deletions
+6 -1
View File
@@ -62,11 +62,16 @@ func run():
check(E.bounded(count), str(count), "integer counts never quantized")
check(E.mul_div(E.of("1e27"), 15, 100), "150000000000000000000000000", "exact percentage")
check(E.mul_div(count, count, count), str(count), "fused product beyond storage range")
var limit = E.of("1e27")
check(E.floor_value(E.mul_div(E.subtract(limit, 1), E.subtract(limit, 3), E.subtract(limit, 2))), "999999999999999999999999997", "fused ratio immediately below whole boundary")
check(E.floor_value(E.divide(E.MIN_INT, -3)), "3074457345618258602", "MIN_INT division preserves quotient")
check(E.floor_value(E.divide(-10, 3)), "-4", "native negative fractional division")
check(E.mul_div(E.MAX_INT, 0, 7), "0", "native zero fused product")
check(E.subtract(E.add(count, 1), count), "1", "single unit at E27")
check(E.floor_value(E.divide(E.subtract(count, 1), count)), "0", "division must not round up a whole object")
check(E.fixed(E.add(count, E.of("0.125")), 3), "1000000000000000000000000001.125", "formatting without oversized intermediate")
check(E.scientific(E.of("9.999999e27"), 2), "1.00E+28", "display rounding at upper boundary")
check(E.eq(E.power(10, -100), E.of("1e-100")), "true", "negative power needs no huge intermediate")
check(absf(E.approx(E.power(10, -100)) / E.approx(E.of("1e-100")) - 1.0) < 1e-15, "true", "negative power retains float precision without huge intermediate")
var largest = E.of("9999999999999999999999999999")
check(E.eq(E.decode(E.encode(largest)), largest), "true", "upper range round trip")
check(E.valid_encoded(E.encode(largest)), "true", "upper range encoding valid")