Numeric Module¶
The rite.numeric module provides numerical operations, mathematical utilities, and statistics.
Overview¶
numeric ¶
Numeric Module¶
Comprehensive numeric operations and utilities.
This module provides utilities organized into semantic submodules: - math: Basic math operations (clamp, abs, sign, power) - conversion: Type conversions (decimal, percentage) - coordinates: Geographic coordinate conversions (DMS) - rounding: Rounding operations (round, floor, ceil, trunc) - statistics: Statistical calculations (mean, median, sum) - range: Range operations (normalize, scale, in_range)
Examples¶
from rite.numeric import math_clamp, statistics_mean math_clamp(5, 0, 10) 5 statistics_mean([1, 2, 3, 4, 5]) 3.0
Legacy Functions¶
from rite.numeric import clamp clamp(5, 0, 10) 5
Functions¶
statistics_max ¶
Find maximum value in list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list[float]
|
List of numbers. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Maximum value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values list is empty. |
Examples:
Notes
Wrapper around built-in max().
statistics_min ¶
Find minimum value in list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list[float]
|
List of numbers. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Minimum value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values list is empty. |
Examples:
Notes
Wrapper around built-in min().
Modules¶
clamp ¶
Clamp Function¶
Clamp a value between minimum and maximum bounds.
Functions¶
clamp ¶
Clamp a value between a lower and upper bound.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val
|
float | None
|
Value to clamp (or None) |
required |
lo
|
float
|
Lower bound |
required |
hi
|
float
|
Upper bound |
required |
Returns:
| Type | Description |
|---|---|
float | None
|
Clamped value or None if input is None |
Example
clamp(5, 0, 10) 5 clamp(-5, 0, 10) 0 clamp(None, 0, 10) None
conversion ¶
Conversion Module¶
Numeric conversion utilities.
This submodule provides utilities for converting between different numeric representations like decimal, percentage, etc.
Examples¶
from rite.numeric.conversion import ( ... conversion_to_decimal, ... conversion_to_percentage ... ) conversion_to_decimal("3.14") Decimal('3.14') conversion_to_percentage(0.25) 25.0
Modules¶
conversion_from_percentage ¶
Decimal to Percentage Converter¶
Convert percentage to decimal.
Examples¶
from rite.numeric.conversion import conversion_from_percentage conversion_from_percentage(25) 0.25
Convert percentage to decimal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Percentage value (0.0 to 100.0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Decimal value (0.0 to 1.0). |
Examples:
>>> conversion_from_percentage(25)
0.25
>>> conversion_from_percentage(50)
0.5
>>> conversion_from_percentage(12.5)
0.125
Notes
Divides by 100.
conversion_to_decimal ¶
Decimal Converter¶
Convert value to Decimal type.
Examples¶
from rite.numeric.conversion import conversion_to_decimal conversion_to_decimal("3.14") Decimal('3.14')
Convert value to Decimal type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | int | float
|
Value to convert (string, int, or float). |
required |
Returns:
| Type | Description |
|---|---|
Decimal | None
|
Decimal object or None if conversion fails. |
Examples:
>>> conversion_to_decimal("3.14")
Decimal('3.14')
>>> conversion_to_decimal(42)
Decimal('42')
>>> conversion_to_decimal("invalid") is None
True
Notes
Returns None on invalid input. Preserves precision for strings.
conversion_to_percentage ¶
Percentage Converter¶
Convert decimal to percentage.
Examples¶
from rite.numeric.conversion import conversion_to_percentage conversion_to_percentage(0.25) 25.0
Convert decimal to percentage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Decimal value (0.0 to 1.0). |
required |
decimals
|
int | None
|
Number of decimal places to round to. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Percentage value (0.0 to 100.0). |
Examples:
>>> conversion_to_percentage(0.25)
25.0
>>> conversion_to_percentage(0.5)
50.0
>>> conversion_to_percentage(0.12345, decimals=2)
12.35
Notes
Multiplies by 100. Optional rounding to specified decimals.
conversion_from_percentage ¶
Decimal to Percentage Converter¶
Convert percentage to decimal.
Examples¶
from rite.numeric.conversion import conversion_from_percentage conversion_from_percentage(25) 0.25
Functions¶
conversion_from_percentage ¶
Convert percentage to decimal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Percentage value (0.0 to 100.0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Decimal value (0.0 to 1.0). |
Examples:
>>> conversion_from_percentage(25)
0.25
>>> conversion_from_percentage(50)
0.5
>>> conversion_from_percentage(12.5)
0.125
Notes
Divides by 100.
conversion_to_decimal ¶
Decimal Converter¶
Convert value to Decimal type.
Examples¶
from rite.numeric.conversion import conversion_to_decimal conversion_to_decimal("3.14") Decimal('3.14')
Functions¶
conversion_to_decimal ¶
Convert value to Decimal type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | int | float
|
Value to convert (string, int, or float). |
required |
Returns:
| Type | Description |
|---|---|
Decimal | None
|
Decimal object or None if conversion fails. |
Examples:
>>> conversion_to_decimal("3.14")
Decimal('3.14')
>>> conversion_to_decimal(42)
Decimal('42')
>>> conversion_to_decimal("invalid") is None
True
Notes
Returns None on invalid input. Preserves precision for strings.
conversion_to_percentage ¶
Percentage Converter¶
Convert decimal to percentage.
Examples¶
from rite.numeric.conversion import conversion_to_percentage conversion_to_percentage(0.25) 25.0
Functions¶
conversion_to_percentage ¶
Convert decimal to percentage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Decimal value (0.0 to 1.0). |
required |
decimals
|
int | None
|
Number of decimal places to round to. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Percentage value (0.0 to 100.0). |
Examples:
>>> conversion_to_percentage(0.25)
25.0
>>> conversion_to_percentage(0.5)
50.0
>>> conversion_to_percentage(0.12345, decimals=2)
12.35
Notes
Multiplies by 100. Optional rounding to specified decimals.
coordinates ¶
Coordinates Module¶
Geographic coordinate conversion utilities.
This submodule provides utilities for converting between decimal degrees and degree-minute-second (DMS) formats.
Examples¶
from rite.numeric.coordinates import ( ... coordinates_to_degree_minute_second, ... coordinates_from_degree_minute_second ... ) coordinates_to_degree_minute_second(12.5) (12, 30, 0.0) coordinates_from_degree_minute_second(12, 30, 0) 12.5
Modules¶
coordinates_from_degree_minute_second ¶
DMS to Float Converter¶
Convert degree-minute-second to float.
Examples¶
from rite.numeric.coordinates import ( ... coordinates_from_degree_minute_second ... ) coordinates_from_degree_minute_second(12, 30, 0) 12.5
Convert degree-minute-second to float.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
degrees
|
int
|
Degrees component. |
required |
minutes
|
int
|
Minutes component (0-59). |
required |
seconds
|
float
|
Seconds component (0-59.999...). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Float representation. |
Examples:
>>> coordinates_from_degree_minute_second(12, 30, 0)
12.5
>>> coordinates_from_degree_minute_second(-12, 30, 30)
-12.508333333333333
>>> coordinates_from_degree_minute_second(0, 0, 30)
0.008333333333333333
Notes
Handles negative degrees correctly.
coordinates_to_degree_minute ¶
Degree-Minute Converter¶
Convert float to degree-minute format.
Examples¶
from rite.numeric.coordinates import coordinates_to_degree_minute coordinates_to_degree_minute(12.5) (12, 30.0)
Convert float to degree-minute format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Float value to convert. |
required |
absolute
|
bool
|
Use absolute value. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[int, float]
|
Tuple of (degrees, minutes). |
Examples:
>>> coordinates_to_degree_minute(12.5)
(12, 30.0)
>>> coordinates_to_degree_minute(-12.5)
(-12, 30.0)
>>> coordinates_to_degree_minute(-12.5, absolute=True)
(12, 30.0)
Notes
Minutes are in range [0, 60).
coordinates_to_degree_minute_second ¶
Degree-Minute-Second Converter¶
Convert float to degree-minute-second format.
Examples¶
from rite.numeric.coordinates import ( ... coordinates_to_degree_minute_second ... ) coordinates_to_degree_minute_second(12.5) (12, 30, 0.0)
Convert float to degree-minute-second format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Float value to convert. |
required |
absolute
|
bool
|
Use absolute value. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[int, int, float]
|
Tuple of (degrees, minutes, seconds). |
Examples:
>>> coordinates_to_degree_minute_second(12.5)
(12, 30, 0.0)
>>> coordinates_to_degree_minute_second(-12.508333)
(-12, 30, 30.0)
>>> coordinates_to_degree_minute_second(-12.5, absolute=True)
(12, 30, 0.0)
Notes
Seconds are in range [0, 60).
coordinates_from_degree_minute_second ¶
DMS to Float Converter¶
Convert degree-minute-second to float.
Examples¶
from rite.numeric.coordinates import ( ... coordinates_from_degree_minute_second ... ) coordinates_from_degree_minute_second(12, 30, 0) 12.5
Functions¶
coordinates_from_degree_minute_second ¶
Convert degree-minute-second to float.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
degrees
|
int
|
Degrees component. |
required |
minutes
|
int
|
Minutes component (0-59). |
required |
seconds
|
float
|
Seconds component (0-59.999...). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Float representation. |
Examples:
>>> coordinates_from_degree_minute_second(12, 30, 0)
12.5
>>> coordinates_from_degree_minute_second(-12, 30, 30)
-12.508333333333333
>>> coordinates_from_degree_minute_second(0, 0, 30)
0.008333333333333333
Notes
Handles negative degrees correctly.
coordinates_to_degree_minute ¶
Degree-Minute Converter¶
Convert float to degree-minute format.
Examples¶
from rite.numeric.coordinates import coordinates_to_degree_minute coordinates_to_degree_minute(12.5) (12, 30.0)
Functions¶
coordinates_to_degree_minute ¶
Convert float to degree-minute format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Float value to convert. |
required |
absolute
|
bool
|
Use absolute value. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[int, float]
|
Tuple of (degrees, minutes). |
Examples:
>>> coordinates_to_degree_minute(12.5)
(12, 30.0)
>>> coordinates_to_degree_minute(-12.5)
(-12, 30.0)
>>> coordinates_to_degree_minute(-12.5, absolute=True)
(12, 30.0)
Notes
Minutes are in range [0, 60).
coordinates_to_degree_minute_second ¶
Degree-Minute-Second Converter¶
Convert float to degree-minute-second format.
Examples¶
from rite.numeric.coordinates import ( ... coordinates_to_degree_minute_second ... ) coordinates_to_degree_minute_second(12.5) (12, 30, 0.0)
Functions¶
coordinates_to_degree_minute_second ¶
Convert float to degree-minute-second format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Float value to convert. |
required |
absolute
|
bool
|
Use absolute value. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[int, int, float]
|
Tuple of (degrees, minutes, seconds). |
Examples:
>>> coordinates_to_degree_minute_second(12.5)
(12, 30, 0.0)
>>> coordinates_to_degree_minute_second(-12.508333)
(-12, 30, 30.0)
>>> coordinates_to_degree_minute_second(-12.5, absolute=True)
(12, 30, 0.0)
Notes
Seconds are in range [0, 60).
float_to_degree_minute ¶
Degree-Minute Conversion¶
Convert float values to degree and minute components.
Example
float_to_degree_minute(12.5) (12, 30.0) float_to_degree_minute(-12.5) (-12, 30.0)
Functions¶
float_to_degree_minute ¶
Split a float value into DM (degree, minute) parts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Float value to split |
required |
absolute
|
bool
|
Obtain the absolute value |
False
|
Returns:
| Type | Description |
|---|---|
tuple[int, float]
|
Tuple containing (degree, minute) |
Example
float_to_degree_minute(12.5) (12, 30.0) float_to_degree_minute(-12.5, absolute=True) (12, 30.0)
float_to_degree_minute_second ¶
Degree-Minute-Second Conversion¶
Convert float values to degree, minute, and second components.
Functions¶
float_to_degree_minute_second ¶
Split a float value into DMS (degree, minute, second) parts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Float value to split |
required |
absolute
|
bool
|
Obtain the absolute value |
False
|
Returns:
| Type | Description |
|---|---|
tuple[int, int, float]
|
Tuple containing (degree, minute, second) |
Example
float_to_degree_minute_second(12.5) (12, 30, 0.0) float_to_degree_minute_second(-12.5, absolute=True) (12, 30, 0.0)
math ¶
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 ¶
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
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:
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
math_abs ¶
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 ¶
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:
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
math_sign ¶
range ¶
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
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
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
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.
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 ¶
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 ¶
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 ¶
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.
rounding ¶
Rounding Module¶
Numeric rounding utilities.
This submodule provides utilities for rounding operations like round, floor, ceil, and truncate.
Examples¶
from rite.numeric.rounding import ( ... rounding_round, ... rounding_floor ... ) rounding_round(3.14159, 2) 3.14 rounding_floor(3.9) 3
Modules¶
rounding_ceil ¶
rounding_floor ¶
rounding_round ¶
Round Function¶
Round number to specified decimal places.
Examples¶
from rite.numeric.rounding import rounding_round rounding_round(3.14159, 2) 3.14
Round number to specified decimal places.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Number to round. |
required |
decimals
|
int
|
Number of decimal places. |
0
|
Returns:
| Type | Description |
|---|---|
float
|
Rounded value. |
Examples:
>>> rounding_round(3.14159, 2)
3.14
>>> rounding_round(3.5)
4.0
>>> rounding_round(123.456, 1)
123.5
Notes
Uses banker's rounding (round half to even).
rounding_ceil ¶
rounding_floor ¶
rounding_round ¶
Round Function¶
Round number to specified decimal places.
Examples¶
from rite.numeric.rounding import rounding_round rounding_round(3.14159, 2) 3.14
Functions¶
rounding_round ¶
Round number to specified decimal places.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Number to round. |
required |
decimals
|
int
|
Number of decimal places. |
0
|
Returns:
| Type | Description |
|---|---|
float
|
Rounded value. |
Examples:
>>> rounding_round(3.14159, 2)
3.14
>>> rounding_round(3.5)
4.0
>>> rounding_round(123.456, 1)
123.5
Notes
Uses banker's rounding (round half to even).
rounding_trunc ¶
statistics ¶
Statistics Module¶
Statistical calculation utilities.
This submodule provides utilities for statistical operations like mean, median, sum, min, and max.
Examples¶
from rite.numeric.statistics import ( ... statistics_mean, ... statistics_median ... ) statistics_mean([1, 2, 3, 4, 5]) 3.0 statistics_median([1, 2, 3, 4, 5]) 3
Functions¶
statistics_max ¶
Find maximum value in list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list[float]
|
List of numbers. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Maximum value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values list is empty. |
Examples:
Notes
Wrapper around built-in max().
statistics_min ¶
Find minimum value in list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list[float]
|
List of numbers. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Minimum value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values list is empty. |
Examples:
Notes
Wrapper around built-in min().
Modules¶
statistics_mean ¶
Mean Calculator¶
Calculate arithmetic mean of numbers.
Examples¶
from rite.numeric.statistics import statistics_mean statistics_mean([1, 2, 3, 4, 5]) 3.0
Calculate arithmetic mean of numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list[float]
|
List of numbers. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Mean value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values list is empty. |
Examples:
>>> statistics_mean([1, 2, 3, 4, 5])
3.0
>>> statistics_mean([10, 20, 30])
20.0
>>> statistics_mean([5.5])
5.5
Notes
Sum divided by count.
statistics_median ¶
Median Calculator¶
Calculate median of numbers.
Examples¶
from rite.numeric.statistics import statistics_median statistics_median([1, 2, 3, 4, 5]) 3
Calculate median of numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list[float]
|
List of numbers. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Median value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values list is empty. |
Examples:
>>> statistics_median([1, 2, 3, 4, 5])
3
>>> statistics_median([1, 2, 3, 4])
2.5
>>> statistics_median([5])
5
Notes
Middle value for odd length. Average of two middle values for even length.
statistics_min_max ¶
Min/Max Functions¶
Find minimum and maximum values.
Examples¶
from rite.numeric.statistics import statistics_min statistics_min([3, 1, 4, 1, 5]) 1
Find maximum value in list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list[float]
|
List of numbers. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Maximum value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values list is empty. |
Examples:
Notes
Wrapper around built-in max().
Find minimum value in list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list[float]
|
List of numbers. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Minimum value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values list is empty. |
Examples:
Notes
Wrapper around built-in min().
statistics_sum ¶
Sum Calculator¶
Calculate sum of numbers.
Examples¶
from rite.numeric.statistics import statistics_sum statistics_sum([1, 2, 3, 4, 5]) 15
statistics_mean ¶
Mean Calculator¶
Calculate arithmetic mean of numbers.
Examples¶
from rite.numeric.statistics import statistics_mean statistics_mean([1, 2, 3, 4, 5]) 3.0
Functions¶
statistics_mean ¶
Calculate arithmetic mean of numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list[float]
|
List of numbers. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Mean value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values list is empty. |
Examples:
>>> statistics_mean([1, 2, 3, 4, 5])
3.0
>>> statistics_mean([10, 20, 30])
20.0
>>> statistics_mean([5.5])
5.5
Notes
Sum divided by count.
statistics_median ¶
Median Calculator¶
Calculate median of numbers.
Examples¶
from rite.numeric.statistics import statistics_median statistics_median([1, 2, 3, 4, 5]) 3
Functions¶
statistics_median ¶
Calculate median of numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list[float]
|
List of numbers. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Median value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values list is empty. |
Examples:
>>> statistics_median([1, 2, 3, 4, 5])
3
>>> statistics_median([1, 2, 3, 4])
2.5
>>> statistics_median([5])
5
Notes
Middle value for odd length. Average of two middle values for even length.
statistics_sum ¶
Sum Calculator¶
Calculate sum of numbers.
Examples¶
from rite.numeric.statistics import statistics_sum statistics_sum([1, 2, 3, 4, 5]) 15
value_to_decimal ¶
Decimal Conversion¶
Convert values to Decimal type with validation.
Functions¶
value_to_decimal ¶
Convert a value into a Decimal and handle any conversion required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Value to convert to Decimal |
required |
Returns:
| Type | Description |
|---|---|
Decimal
|
Decimal representation of the value |
Raises:
| Type | Description |
|---|---|
ValueError
|
If value is None or cannot be converted to Decimal |
Example
value_to_decimal(12.5) Decimal('12.5') value_to_decimal("12.5") Decimal('12.5')
Submodules¶
Math¶
Basic mathematical operations.
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 ¶
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 ¶
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:
Notes
If minimum > maximum, behavior is undefined.
math_sign ¶
math_pow ¶
Power Function¶
Raise a number to a power.
Examples¶
from rite.numeric.math import math_pow math_pow(2, 3) 8.0
Rounding¶
Number rounding utilities.
Rounding Module¶
Numeric rounding utilities.
This submodule provides utilities for rounding operations like round, floor, ceil, and truncate.
Examples¶
from rite.numeric.rounding import ( ... rounding_round, ... rounding_floor ... ) rounding_round(3.14159, 2) 3.14 rounding_floor(3.9) 3
Modules¶
rounding_round ¶
Round Function¶
Round number to specified decimal places.
Examples¶
from rite.numeric.rounding import rounding_round rounding_round(3.14159, 2) 3.14
Functions¶
rounding_round ¶
Round number to specified decimal places.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Number to round. |
required |
decimals
|
int
|
Number of decimal places. |
0
|
Returns:
| Type | Description |
|---|---|
float
|
Rounded value. |
Examples:
>>> rounding_round(3.14159, 2)
3.14
>>> rounding_round(3.5)
4.0
>>> rounding_round(123.456, 1)
123.5
Notes
Uses banker's rounding (round half to even).
rounding_ceil ¶
rounding_floor ¶
Statistics¶
Statistical calculations.
Statistics Module¶
Statistical calculation utilities.
This submodule provides utilities for statistical operations like mean, median, sum, min, and max.
Examples¶
from rite.numeric.statistics import ( ... statistics_mean, ... statistics_median ... ) statistics_mean([1, 2, 3, 4, 5]) 3.0 statistics_median([1, 2, 3, 4, 5]) 3
Modules¶
statistics_mean ¶
Mean Calculator¶
Calculate arithmetic mean of numbers.
Examples¶
from rite.numeric.statistics import statistics_mean statistics_mean([1, 2, 3, 4, 5]) 3.0
Functions¶
statistics_mean ¶
Calculate arithmetic mean of numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list[float]
|
List of numbers. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Mean value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values list is empty. |
Examples:
>>> statistics_mean([1, 2, 3, 4, 5])
3.0
>>> statistics_mean([10, 20, 30])
20.0
>>> statistics_mean([5.5])
5.5
Notes
Sum divided by count.
statistics_median ¶
Median Calculator¶
Calculate median of numbers.
Examples¶
from rite.numeric.statistics import statistics_median statistics_median([1, 2, 3, 4, 5]) 3
Functions¶
statistics_median ¶
Calculate median of numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list[float]
|
List of numbers. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Median value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values list is empty. |
Examples:
>>> statistics_median([1, 2, 3, 4, 5])
3
>>> statistics_median([1, 2, 3, 4])
2.5
>>> statistics_median([5])
5
Notes
Middle value for odd length. Average of two middle values for even length.
statistics_sum ¶
Sum Calculator¶
Calculate sum of numbers.
Examples¶
from rite.numeric.statistics import statistics_sum statistics_sum([1, 2, 3, 4, 5]) 15
statistics_min_max ¶
Min/Max Functions¶
Find minimum and maximum values.
Examples¶
from rite.numeric.statistics import statistics_min statistics_min([3, 1, 4, 1, 5]) 1
Functions¶
statistics_max ¶
Find maximum value in list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list[float]
|
List of numbers. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Maximum value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values list is empty. |
Examples:
Notes
Wrapper around built-in max().
statistics_min ¶
Find minimum value in list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list[float]
|
List of numbers. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Minimum value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values list is empty. |
Examples:
Notes
Wrapper around built-in min().
Range¶
Range operations.
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 ¶
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 ¶
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 ¶
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.