sluyspy.numerics module

Numerics stuff for the sluyspy package

sluyspy.numerics.eps = 2.220446049250313e-16

2.2204460492503131e-16

Type:

Smallest value for which 1+eps != 1

sluyspy.numerics.eps1 = 1.0000000000000002

1 + 2.2204460492503131e-16

Type:

Smallest value larger than 1

sluyspy.numerics.map_pi_pi(ang)[source]

Map an (array of) angle(s) to lie between -PI and +PI.

Parameters:

ang (float) – (Array of) angle(s).

Returns:

(Array) of angles between -PI and +PI.

Return type:

(float)

sluyspy.numerics.nint(val)[source]

Convert a float to the nearest integer with proper rounding.

Parameters:

val (float) – Value to convert.

Returns:

Nearest integer (or float(‘nan’)).

Return type:

(int)

sluyspy.numerics.sigdig(num, dig=14)[source]

Return a string with a given number using (at most) the specified number of significant digits.

Parameters:
  • num (float) – Number to print.

  • dig (int) – Number of significant digits to use (optional; defaults to 14 to avoid machine rounding).

Returns:

Struct containing command-line arguments.

Return type:

(struct)

Note

  • Trailing zeros are NOT printed - hence, this function does not EXACTLY print the desired number of significant digits;

  • 0.075 with a single digit is printed as 0.07, hence multiply with eps1!

See:

E.g. the discussions here: https://stackoverflow.com/q/3410976/1386750

sluyspy.numerics.tiny = 5e-324

4.9406564584124654e-324

Type:

Smallest value larger than 0