Skip to content

Range

The rite.numeric.range submodule offers helpers for working with numeric ranges, normalization, and scaling.

Range Module

Range and normalization utilities.

This submodule provides utilities for range operations like checking if values are in range, normalizing, and scaling.

Examples

from rite.numeric.range import ( ... range_in_range, ... range_normalize ... ) range_in_range(5, 0, 10) True range_normalize(5, 0, 10) 0.5

Modules

range_in_range

In Range Checker

Check if value is within range.

Examples

from rite.numeric.range import range_in_range range_in_range(5, 0, 10) True

Functions

range_in_range(value: float, minimum: float, maximum: float, inclusive: bool = True) -> bool

Check if value is within range.

Parameters:

Name Type Description Default
value float

Value to check.

required
minimum float

Lower bound.

required
maximum float

Upper bound.

required
inclusive bool

Include bounds in check.

True

Returns:

Type Description
bool

True if value is in range.

Examples:

>>> range_in_range(5, 0, 10)
True
>>> range_in_range(0, 0, 10, inclusive=True)
True
>>> range_in_range(0, 0, 10, inclusive=False)
False
>>> range_in_range(15, 0, 10)
False
Notes

Inclusive by default (<=, >=). Non-inclusive uses (<, >).

range_normalize

Normalize Function

Normalize value to 0-1 range.

Examples

from rite.numeric.range import range_normalize range_normalize(5, 0, 10) 0.5

Functions

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

Normalize value to 0-1 range.

Parameters:

Name Type Description Default
value float

Value to normalize.

required
minimum float

Minimum of input range.

required
maximum float

Maximum of input range.

required

Returns:

Type Description
float

Normalized value (0.0 to 1.0).

Examples:

>>> range_normalize(5, 0, 10)
0.5
>>> range_normalize(0, 0, 10)
0.0
>>> range_normalize(10, 0, 10)
1.0
Notes

Formula: (value - min) / (max - min). Assumes maximum > minimum.

range_scale

Scale Function

Scale value from one range to another.

Examples

from rite.numeric.range import range_scale range_scale(5, 0, 10, 0, 100) 50.0

Functions

range_scale(value: float, from_min: float, from_max: float, to_min: float, to_max: float) -> float

Scale value from one range to another.

Parameters:

Name Type Description Default
value float

Value to scale.

required
from_min float

Source range minimum.

required
from_max float

Source range maximum.

required
to_min float

Target range minimum.

required
to_max float

Target range maximum.

required

Returns:

Type Description
float

Scaled value.

Examples:

>>> range_scale(5, 0, 10, 0, 100)
50.0
>>> range_scale(0, 0, 10, 100, 200)
100.0
>>> range_scale(10, 0, 10, 100, 200)
200.0
Notes

Linear interpolation between ranges.

options: show_root_heading: true show_source: false heading_level: 2