algolib.numerics package
Submodules
algolib.numerics.constants module
Centralized numerical constants for algolib.
No imports from math or third-party libs: pure Python floats only.
Values are given either as exact decimal, or with comments showing hex-float for traceability.
Includes Cody–Waite style splits for stable range-reduction in exp/sin/cos.
- algolib.numerics.constants.copysign1(x: float, y: float) float [源代码]
Return :math:\abs{x} with the sign of y. No math module, handles ±0.0 and NaN.
- algolib.numerics.constants.pow2_int(k: int) float [源代码]
Compute 2**k using only multiplies (supports negative k) with IEEE754-style bounds.
- Behavior:
k > 1023 -> raise NumericOverflowError (subclass of OverflowError)
k < -1074 -> 0.0 (underflow to zero)
-1074 <= k <= -1023 -> exact subnormal via halving from DBL_MIN
otherwise -> exponentiation-by-squaring (<= 1023 以及 >= -1022)
algolib.numerics.diff module
- algolib.numerics.diff.derivative_central(f: Callable[[float], float], x: float, *, h: float | None = None, max_iter: int = 6) float [源代码]
Central difference derivative approximation with Richardson extrapolation.
Useful when f does not support complex input. Accuracy is O(h^2) per step and improved by extrapolation.
algolib.numerics.trig module
- algolib.numerics.trig.cos(x: Any) float [源代码]
Cosine of an angle (system backend).
- 参数:
x (float) -- Input angle in radians.
- 返回:
cos(x)
evaluated by the active numerics backend.- 返回类型:
float
- algolib.numerics.trig.sin(x: Any) float [源代码]
Sine of an angle (system backend).
- 参数:
x (float) -- Input angle in radians.
- 返回:
sin(x)
evaluated by the active numerics backend.- 返回类型:
float
- algolib.numerics.trig.tan(x: Any) float [源代码]
Tangent of an angle (system backend).
备注
Argument-reduction and non-finite handling are performed inside the active backend (see
_backend.SystemTrigBackend.tan
). Keeping this wrapper free of extra reduction ensures consistent periodicity tests.- 参数:
x (float) -- Input angle in radians.
- 返回:
tan(x)
evaluated by the active numerics backend.- 返回类型:
float
algolib.numerics.trig_pure module
Numerical trig functions: sin / cos / tan
No stdlib math usage in implementation
Cody–Waite style range reduction by π/2
Polynomial approximation on [-π/4, π/4]