stko.cap_absolute_value

stko.cap_absolute_value(value, max_absolute_value=1)[source]

Returns value with absolute value capped at max_absolute_value.

Particularly useful in passing values to trignometric functions where numerical errors may result in an argument > 1 being passed in.

This code is modified from the pymatgen source code [2].

Parameters:
  • value (float) – Value to cap.

  • max_absolute_value (float) – Absolute value to cap value at. Defaults to 1.

Returns:

value capped at max_absolute_value with sign preserved.

Return type:

float

References