finesse.utilities.numbers.clip_with_tolerance

finesse.utilities.numbers.clip_with_tolerance(number: float, _min: float, _max: float, tol: float = 1e-12) float[source]

Clips a number to the range [_min, _max] if it is in [_min - tol, _max + tol], otherwise just returns the number.

Useful for correcting numerical precision errors after calculating physical quantities.

Parameters
numberfloat

Number to clip

_minfloat

lower end of clipping range

_maxfloat

higher end of clipping range

tolfloat, optional

Absolute tolerance, by default 1e-12

Returns
float

The clipped number