bag.math

This package defines design template classes.

Submodules

Package Contents

Functions

get_si_prefix(→ Tuple[int, str])

float_to_si_string(→ str)

Converts the given floating point number to a string using SI prefix.

si_string_to_float(si_str)

Converts the given string with SI prefix to float.

gcd(→ int)

Compute greatest common divisor of two positive integers.

lcm(→ int)

Compute least common multiple of all numbers in the given list.

bag.math.get_si_prefix(num: float) Tuple[int, str][source]
bag.math.float_to_si_string(num: float, precision: int = 6) str[source]

Converts the given floating point number to a string using SI prefix.

Parameters:
  • num (float) – the number to convert.

  • precision (int) – number of significant digits, defaults to 6.

Returns:

ans – the string representation of the given number using SI suffix.

Return type:

str

bag.math.si_string_to_float(si_str)[source]

Converts the given string with SI prefix to float.

Parameters:

si_str (str) – the string to convert

Returns:

ans – the floating point value of the given string.

Return type:

float

bag.math.gcd(a: int, b: int) int[source]

Compute greatest common divisor of two positive integers.

Parameters:
  • a (int) – the first number.

  • b (int) – the second number.

Returns:

ans – the greatest common divisor of the two given integers.

Return type:

int

bag.math.lcm(arr: Iterable[int], init: int = 1) int[source]

Compute least common multiple of all numbers in the given list.

Parameters:
  • arr (Iterable[int]) – a list of integers.

  • init (int) – the initial LCM. Defaults to 1.

Returns:

ans – the least common multiple of all the given numbers.

Return type:

int