Mathematical Functions¶
Mathematical utility functions for number formatting and logarithm calculations.
rndsf
¶
Round number to specified significant figures.
Parameters:
-
(x¶Union[int, float]) –Number to round.
-
(sf¶int) –Number of significant figures (2-10).
-
(zero¶Optional[float], default:None) –Optional zero threshold (default: 10^-sf).
Returns:
-
str–Formatted string representation with specified significant figures.
Raises:
-
TypeError–If arguments have invalid types.
-
ValueError–If arguments have invalid values.
Examples:
ln
¶
Return logarithm to specified base.
Parameters:
-
(x¶float) –Number to obtain logarithm of.
-
(base¶Union[int, str], default:'e') –Base to use - 2, 10, or 'e' for natural logarithm.
Returns:
-
float–Logarithm of x to the specified base.
Raises:
-
TypeError–If arguments have invalid types.
-
ValueError–If arguments have invalid values.
Example
ln(10, 10) 1.0 ln(8, 2) 3.0 ln(2.718281828459045) # e 1.0
Usage Examples¶
Significant Figure Rounding¶
from causaliq_core.utils import rndsf
# Basic rounding
rndsf(1.23456789, 4) # Returns '1.235'
# Small numbers
rndsf(0.000123, 3) # Returns '0.000123'
# Large numbers
rndsf(1234567, 3) # Returns '1230000.0'
# Custom zero threshold
rndsf(0.0001, 3, zero=0.001) # Returns '0.0'