maths.number_of_digits¶
Functions¶
|
Benchmark multiple functions, with three different length int values. |
|
Find the number of digits in a number. |
|
Find the number of digits in a number. |
|
Find the number of digits in a number. |
Module Contents¶
- maths.number_of_digits.benchmark() None ¶
Benchmark multiple functions, with three different length int values.
- maths.number_of_digits.num_digits(n: int) int ¶
Find the number of digits in a number.
>>> num_digits(12345) 5 >>> num_digits(123) 3 >>> num_digits(0) 1 >>> num_digits(-1) 1 >>> num_digits(-123456) 6 >>> num_digits('123') # Raises a TypeError for non-integer input Traceback (most recent call last): ... TypeError: Input must be an integer
- maths.number_of_digits.num_digits_fast(n: int) int ¶
Find the number of digits in a number. abs() is used as logarithm for negative numbers is not defined.
>>> num_digits_fast(12345) 5 >>> num_digits_fast(123) 3 >>> num_digits_fast(0) 1 >>> num_digits_fast(-1) 1 >>> num_digits_fast(-123456) 6 >>> num_digits('123') # Raises a TypeError for non-integer input Traceback (most recent call last): ... TypeError: Input must be an integer
- maths.number_of_digits.num_digits_faster(n: int) int ¶
Find the number of digits in a number. abs() is used for negative numbers
>>> num_digits_faster(12345) 5 >>> num_digits_faster(123) 3 >>> num_digits_faster(0) 1 >>> num_digits_faster(-1) 1 >>> num_digits_faster(-123456) 6 >>> num_digits('123') # Raises a TypeError for non-integer input Traceback (most recent call last): ... TypeError: Input must be an integer