Skip to content

Machine Limit

Particula Index / Particula / Util / Machine Limit

Auto-generated documentation for particula.util.machine_limit module.

get_safe_exp

Show source in machine_limit.py:12

Compute the exponential of each element in the input array, with overflow protection.

The exponential is calculated using: - y = exp(x), where x is clipped to avoid exceeding machine limits.

Arguments

  • value : Array-like of values to exponentiate.

Returns

  • np.ndarray of exponentiated values, with machine-level clipping.

Examples

Example Usage
import numpy as np
import particula as par

arr = np.array([0, 10, 1000])
print(par.get_safe_exp(arr))
# Output: [1.00000000e+000 2.20264658e+004 1.79769313e+308]

References

  • "Floating Point Arithmetic," NumPy Documentation, NumPy.org.

Signature

def get_safe_exp(value: ArrayLike) -> np.ndarray: ...

get_safe_log

Show source in machine_limit.py:44

Compute the natural logarithm of each element in the input array, with underflow protection.

The natural log is calculated using: - y = ln(x), where x is clipped away from zero to maintain positivity.

Arguments

  • value : Array-like of values for logarithm calculation.

Returns

  • np.ndarray of natural logarithms, with machine-level clipping.

Examples

Example Usage
import numpy as np
import particula as par

arr = np.array([1e-320, 1.0, 10.0])
print(get_safe_log(arr))
# Output: [-7.40545337e+02  0.00000000e+00  2.30258509e+00]

References

  • "Logarithms and Machine Precision," NumPy Documentation, NumPy.org.

Signature

def get_safe_log(value: ArrayLike) -> np.ndarray: ...

get_safe_log10

Show source in machine_limit.py:76

Compute the base-10 logarithm of each element in the input array, with underflow protection.

The base-10 log is calculated using: - y = log10(x), where x is clipped away from zero to maintain positivity.

Arguments

  • value : Array-like of values for base-10 logarithm calculation.

Returns

  • np.ndarray of base-10 logarithms, with machine-level clipping.

Examples

Example Usage
import numpy as np
import particula as par

arr = np.array([1e-320, 1.0, 1000.0])
print(par.get_safe_log10(arr))
# Output: [-320.           0.           3.        ]

References

  • "Logarithms and Machine Precision," NumPy Documentation, NumPy.org.

Signature

def get_safe_log10(value: ArrayLike) -> np.ndarray: ...