Home /Modules/java/MATH-MAP.md

MATH-MAP.md

lib/java/jdk-28/MATH-MAP.md · 69 line(s) · markdown

Mapping Java static Math / StrictMath references to SLeeLa

Container. Every Math / StrictMath name in this document is housed in the Java container (/lib/java/jdk-28, selected by import java.jdk-28;). It is not part of the SLeeLa specification (SLEELA.syntax section 38.4). A bare Math without that import is not a Java reference. A translator records the reference as java.jdk-28:java.lang.Math.

Rule (PURPOSE.md, row 5): a static Math reference is mapped, not rewritten. The translator keeps the call as written and the SLeeLa function of the same name answers it.

Java sourceSLeeLa sourceImplemented by
Math.f(args)Math.f(args)jdk-28/java.base/java/lang/Math.sleela (real statics)
StrictMath.f(args)StrictMath.f(args)StrictMath.sleela, each static returns Math.f(args)
Math.PI, Math.E, Math.TAUsamestatic final double in Math.sleela

A program selects this tier with import java.jdk-28; (see examples/java/jdk-28/MathRun.sleela, StrictMathRun.sleela, MathExactRun.sleela).

Member groups

GroupMembers
Sign and extremesabs, absExact, max, min, signum, copySign, clamp
Roundingfloor, ceil, rint, round
Roots and powerssqrt, cbrt, hypot, pow, exp, expm1, log, log10, log1p
Trigonometrysin, cos, tan, asin, acos, atan, atan2, sinh, cosh, tanh, toRadians, toDegrees
Integer divisionfloorDiv, floorMod, ceilDiv, ceilMod, divideExact, floorDivExact, ceilDivExact
Exact arithmetic (64-bit range, ArithmeticException)addExact, subtractExact, multiplyExact, negateExact, incrementExact, decrementExact, toIntExact, powExact
Wide productsmultiplyFull, multiplyHigh, unsignedMultiplyHigh
Unsigned exactunsignedMultiplyExact, unsignedPowExact
Floating-point structurefma, scalb, getExponent, ulp, nextUp, nextDown, nextAfter, IEEEremainder
Randomrandom

Evidence: examples/java/differential/MathStatics.{java,sleela} runs these on a real JDK and on the SLeeLa VM and the output must be identical (examples/java/differential/run-differential.sh).

Overload collapse

The VM has one integer kind (64-bit) and one floating kind, so int/long and float/double overloads cannot be told apart at a call site. Overload ties go to source order, and the long forms are declared first, so every *Exact call checks the 64-bit range. A Java program that depends on the 32-bit Math.addExact(int, int) overflow, or on float rounding, needs the explicit wrap (Math.toIntExact(...), PURPOSE.md row 16).

Why not the native math facade

import math; offers math.sqrt, math.sin, math.pow and so on (impl/subjects/math/math_native.cpp). It was compared with a real JDK and is not a drop-in for java.lang.Math:

CallJavanative math.*
log(0.0)-Infinity0
pow(0.0, -1.0)Infinity1
pow(-8.0, 0.3333333333)NaN1
sqrt(-1.0)NaN0
trunc, sign, fmodno Math memberextra names only

There is also no asin, acos, atan, atan2, sinh, cosh, tanh, cbrt, rint, round or any *Exact member in the facade. The translator therefore maps to Math.* (which keeps the Java special cases) and leaves math.* for code written directly in SLeeLa.