Core Library
The core library provides essential numerical functions including splitting operations, predicates, exponent manipulation, and context queries.
Splitting Functions
- fpy2.libraries.core.split(x, n)
Splits
xinto two parts:all digits of
xthat are above thenth digitall digits of
xthat are at or below thenth digit
The operation is performed exactly.
- Parameters:
- Returns:
Tuple of (high_part, low_part)
- Return type:
- Raises:
ValueError – if
nis not an integer
Special cases:
if
xis NaN, the result is(NaN, NaN)if
xis infinite, the result is(x, x)
Primitive: This is an FPy primitive with context parameter ‘R’ and return context (‘R’, ‘R’).
- fpy2.libraries.core.modf(x)
Decomposes
xinto its integral and fractional parts. The operation is performed exactly.- Parameters:
x (Float) – Value to decompose
- Returns:
Tuple of (fractional_part, integral_part)
- Return type:
Special cases (mirroring C/C++
modf):if
xis+/-0, the result is(+/-0, +/-0)if
xis+/-Inf, the result is(+/-0, +/-Inf)if
xis NaN, the result is(NaN, NaN)
Primitive: This is an FPy primitive with context parameter ‘R’ and return context (‘R’, ‘R’).
- fpy2.libraries.core.frexp(x)
Decomposes
xinto its mantissa and exponent. The computation is performed exactly.- Parameters:
x (Float) – Value to decompose
- Returns:
Tuple of (mantissa, exponent)
- Return type:
Special cases (mirroring C/C++
frexp):if
xis NaN, the result is(NaN, NaN)if
xis infinity, the result is(x, NaN)if
xis zero, the result is(x, 0)
Primitive: This is an FPy primitive with context parameter ‘R’ and return context (‘R’, ‘R’).
Predicates
- fpy2.libraries.core.isinteger(x)
Checks if
xis an integer.- Parameters:
x (Real) – Value to check
- Returns:
True if
xis an integer, False otherwise- Return type:
bool
- fpy2.libraries.core.isnar(x)
Checks if
xis either NaN or infinity (Not-a-Real).- Parameters:
x (Real) – Value to check
- Returns:
True if
xis NaN or infinity, False otherwise- Return type:
bool
Exponent Functions
- fpy2.libraries.core.logb(x)
Returns the normalized exponent of
x.Special cases:
If
x == 0, the result is-INFINITYIf
xis NaN, the result is NaNIf
xis infinite, the result isINFINITY
Primitive: This is an FPy primitive with context parameter ‘R’ and return context ‘R’.
- fpy2.libraries.core.ldexp(x, n)
Computes
x * 2**nwith correct rounding.- Parameters:
- Returns:
Result of
x * 2**n- Return type:
- Raises:
ValueError – if
nis not an integer
Special cases:
If
xis NaN, the result is NaNIf
xis infinite, the result is infinite
Primitive: This is an FPy primitive with context parameter ‘R’ and return context ‘R’.
- fpy2.libraries.core.max_e(xs)
Computes the largest (normalized) exponent of the subset of finite, non-zero elements of
xs.- Parameters:
xs (list[Real]) – List of values
- Returns:
Tuple of (largest_exponent, exists_non_zero)
- Return type:
tuple[Real, bool]
Returns the largest exponent and whether any such element exists. If all elements are zero, infinite, or NaN, the exponent is
0.Function context: Uses INTEGER context.
Context Operations
- fpy2.libraries.core.max_p()
Returns the maximum precision of the current context. This is a no-op for the
RealContext.- Returns:
Maximum precision
- Return type:
- Raises:
ValueError – if the context does not have a maximum precision
Primitive: This is an FPy primitive with context parameter ‘R’ and return context ‘R’.
- fpy2.libraries.core.min_n()
Returns the least absolute digit of the current context. This is the position of the most significant digit that can never be represented.
- Returns:
Least absolute digit position
- Return type:
- Raises:
ValueError – if the context does not have a least absolute digit
Primitive: This is an FPy primitive with context parameter ‘R’ and return context ‘R’.