Scalar mathematics
Use checked native Float64 square root, powers, exponential, natural logarithm and trigonometry with explicit domains and errors.
aner.math provides native CPU scalar mathematics for Float64 values. Import the module, then call math.sqrt, math.pow, natural math.log, exponential and trigonometric functions. Inputs and results are checked against each function's domain and the finite Float64 range.
This module requires the updated native development runtime built from this source. Earlier published binaries may reject aner.math; match the executable to this documentation.
Run a complete example
After installing Aner, save this program as math_basic.aner, or use the complete bundled source:
import aner.math
let hypotenuse = math.sqrt(math.pow(base: 3.0, exponent: 2.0) + math.pow(4.0, 2.0))
print(hypotenuse)
print(math.abs(-3.5))
print(math.pow(exponent: 3.0, base: -2.0))
print(math.exp(0.0))
print(math.log(1.0))
print(math.sin(0.0))
print(math.cos(0.0))
print(math.tan(0.0))
print(math.sqrt(Float64(4)))
print(math.pow(0.0, 0.0))
let pi = 3.141592653589793
print(math.abs(math.sin(pi / 6.0) - 0.5) < 0.000000000001)aner check math_basic.aner
aner run math_basic.anerExpected output:
5.0
3.5
-8.0
1.0
0.0
0.0
1.0
0.0
2.0
1.0
trueAll numerical arguments are explicitly Float64. math.sqrt(4) fails static checking; math.sqrt(4.0) and math.sqrt(Float64(4)) are valid. Named arguments bind by the labels below and are evaluated once in source order.
Native API
| Signature | Result and domain |
|---|---|
math.sqrt(value: Float64) | Float64; square root of a nonnegative value. Signed zero is accepted. |
math.abs(value: Float64) | Float64; absolute magnitude, including positive zero for -0.0. |
math.pow(base: Float64, exponent: Float64) | Float64; real power. A negative base requires an integral Float64 exponent. Zero with a negative exponent fails; 0.0 raised to 0.0 is explicitly 1.0. |
math.exp(value: Float64) | Float64; natural exponential. |
math.log(value: Float64) | Float64; natural logarithm of a strictly positive value. |
math.sin(value: Float64) | Float64; sine of an angle expressed in radians. |
math.cos(value: Float64) | Float64; cosine of an angle expressed in radians. |
math.tan(value: Float64) | Float64; tangent of an angle expressed in radians. |
Trigonometric arguments are raw Float64 radians. aner.units provides scalar quantities, absolute temperature points and unit literals through a bounded registry; math calls require an explicit .value() numerical boundary. Unit typed angles remain planned. Use SemanticTensor and EvidenceTensor for coordinates and the supported source aware uncertainty model.
Numerical behavior and errors
Every input must be finite. Float64 source literals are checked by the parser, while ordinary scalar arithmetic can produce infinity or NaN; passing either into a math function fails explicitly. Domain and range failures produce a source located R3601 diagnostic containing the native code and operation:
| Native code | Meaning and example |
|---|---|
E_MATH_NONFINITE | An argument is infinity or NaN, for example math.sqrt(1.0 / 0.0). |
E_MATH_DOMAIN | The real valued operation is undefined under the declared domain, for example math.sqrt(-1.0), math.log(0.0) or math.pow(-4.0, 0.5). |
E_MATH_RANGE | A result overflows the finite Float64 range, or a mathematically nonzero exp/pow result rounds to zero. Examples include math.exp(1000.0), math.exp(-1000.0) and math.pow(0.5, 2000.0). |
Finite representable subnormal results remain valid. math.pow(2.0, -1074.0) returns the smallest positive Float64 subnormal on the supported IEEE Float64 platforms. The exact zero result of a positive power of zero is valid. No implicit clamping, epsilon substitution or conversion of errors into a missing value occurs.
Tangent uses the supplied floating point angle. A finite approximation to pi / 2 can produce a large finite result and is accepted; the API applies no guessed near pole cutoff. Users can apply a domain specific tolerance before evaluating an ill conditioned expression.
Results follow the platform's native mathematical library, with normal Float64 rounding. Cross platform bitwise identity and correctly rounded transcendental results are not guaranteed. Last bit differences and argument reduction behavior can depend on the native library. The functions do not inspect stale errno or floating point exception flags to decide admission.
Computation boundaries
These functions perform scalar CPU operations and return plain Float64. They do not create Tensor differentiation graphs or propagate measurement uncertainty. Array vectorization, accelerator math and typed scalar units require their own supported APIs.
The functions are permitted in checked isolated repetition tasks, including admitted helper functions. A math failure in an iteration fails the repetition through its normal source located task diagnostic; no incomplete result batch is returned. Worker count does not change a task's explicit inputs, random draws or mathematical formulas.
Continue with Tensor for numerical arrays and differentiation, aner.science for measurement uncertainty, or the heat diffusion study for a complete numerical research workflow.
See the runnable Math example page and download its source.