pencil.math.general

Contains the definitions various short mathematicl function.

Functions

is_number(num_str)

is_number(num_str)

is_int(num_str)

is_int(num_str)

is_float(num_str)

is_float(num_str)

is_iterable(i)

is_iterable(i)

log_range(a, b[, include_ab, finer_factor])

log_range(a, b, include_ab=False, finer_factor=1)

round_next_magnitude(num)

round_next_magnitude(num)

natural_sort(string_list[, reverse])

natural_sort(string_list, reverse=False)

Module Contents

pencil.math.general.is_number(num_str)

is_number(num_str)

Checks if string s is a number.

Parameters:

num_str (string) – String containing the number to be checked.

pencil.math.general.is_int(num_str)

is_int(num_str)

Checks if string num_str is an int.

Parameters:

num_str (string) – String containing the number to be checked.

pencil.math.general.is_float(num_str)

is_float(num_str)

Checks if string num_str is a float.

Parameters:

num_str (string) – String containing the number to be checked.

pencil.math.general.is_iterable(i)

is_iterable(i)

Checks if i is an iterable.

Parameters:

i (obj) – Object to be checked.

pencil.math.general.log_range(a, b, include_ab=False, finer_factor=1)

log_range(a, b, include_ab=False, finer_factor=1)

Compute the logarithmic range between a and b.

Parameters:
  • a (float) – Start and end values.

  • b (float) – Start and end values.

  • include_ab (bool) – Always include a and b in the interval.

  • finer_factor (float) – Factor by which the range is being refined.

Examples

>>> log_range(4, 40)
[4, 5, 6, 7, 8, 9, 10, 20, 30, 40]
pencil.math.general.round_next_magnitude(num)

round_next_magnitude(num)

Rounds a number up to the next multiple of 10, e.g. 4.56 will be rounded to 10.

Parameters:

num (float) – Number to be rounded.

pencil.math.general.natural_sort(string_list, reverse=False)

natural_sort(string_list, reverse=False)

Sort a list of float numbers in strings in a natural way.

Parameters:
  • string_list (list of strings) – Will be converted to float, then sorted.

  • reverse (bool) – If true, list in reverse order.