Skip to content

Math

The rite.numeric.math submodule provides small, focused mathematical helpers such as clamp, sign, and power.

Math Module

Basic mathematical operations.

This submodule provides utilities for basic math operations like clamping, absolute value, sign, and power.

Examples

from rite.numeric.math import math_clamp, math_sign math_clamp(5, 0, 10) 5 math_sign(-5) -1

Modules

math_abs

Absolute Value

Get absolute value of a number.

Examples

from rite.numeric.math import math_abs math_abs(-5) 5

Functions

math_abs(value: float) -> float

Get absolute value of a number.

Parameters:

Name Type Description Default
value float

Number to get absolute value of.

required

Returns:

Type Description
float

Absolute value.

Examples:

>>> math_abs(-5)
5
>>> math_abs(5)
5
>>> math_abs(0)
0
Notes

Wrapper around built-in abs() for consistency.

math_clamp

Clamp Function

Clamp a value between minimum and maximum bounds.

Examples

from rite.numeric.math import math_clamp math_clamp(5, 0, 10) 5

Functions

math_clamp(value: float, minimum: float, maximum: float) -> float

Clamp a value between minimum and maximum bounds.

Parameters:

Name Type Description Default
value float

Value to clamp.

required
minimum float

Lower bound.

required
maximum float

Upper bound.

required

Returns:

Type Description
float

Clamped value.

Examples:

>>> math_clamp(5, 0, 10)
5
>>> math_clamp(-5, 0, 10)
0
>>> math_clamp(15, 0, 10)
10
Notes

If minimum > maximum, behavior is undefined.

math_pow

Power Function

Raise a number to a power.

Examples

from rite.numeric.math import math_pow math_pow(2, 3) 8.0

Functions

math_pow(base: float, exponent: float) -> float

Raise a number to a power.

Parameters:

Name Type Description Default
base float

Base number.

required
exponent float

Exponent.

required

Returns:

Type Description
float

Result of base ** exponent.

Examples:

>>> math_pow(2, 3)
8.0
>>> math_pow(5, 2)
25.0
>>> math_pow(2, -1)
0.5
Notes

Wrapper around ** operator for consistency.

math_sign

Sign Function

Get sign of a number (-1, 0, or 1).

Examples

from rite.numeric.math import math_sign math_sign(-5) -1

Functions

math_sign(value: float) -> int

Get sign of a number.

Parameters:

Name Type Description Default
value float

Number to get sign of.

required

Returns:

Type Description
int

-1 if negative, 0 if zero, 1 if positive.

Examples:

>>> math_sign(-5)
-1
>>> math_sign(0)
0
>>> math_sign(5)
1
Notes

Uses integer comparison for zero check.

options: show_root_heading: true show_source: false heading_level: 2