abs_cap

sknano.core.math.abs_cap(val, max_abs_val=1)[source] [edit on github][source]

Returns the value with its absolute value capped at max_abs_val.

Modified implementation of pymatgen.util.num_utils.abs_cap.

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

Parameters:
  • val (float) –
  • max_abs_val (float) – The maximum absolute value for val. Default=1.
Returns:

Return type:

val if abs(val) < max_abs_val else sign of val * max_abs_val.