dhp.math

fequal

compare to floats to see if they are equal within a tolerance

fequal(num1, num2, tolerance=0.000001)

return True if num1 is within tolerance of num2, else false

Parameters:
  • num1 – float
  • num2 – float
  • tolerance – float
Return type:

boolean

from dhp.math import fequal

assert fequal(1.123456, 1.1234561)

Use case: comparing floats can be interesting due to internal representations

is_even

returns True if integer is even

is_even(num)
Parameters:num – int
Return type:boolean

is_odd

returns True if integer is odd

is_odd(num)
Parameters:num – int
Return type:boolean

mean

returns the Arithmetic mean (a/k/a average) of a list of numbers

mean(lst)
Parameters:list – float | int | mixed
Return type:float

gmean

returns the Geometric mean of a list of numbers

gmean(lst)
Parameters:list – float | int | mixed
Return type:float

hmean

returns the Harmonic mean of a list of numbers

hmean(lst)
Parameters:list – float | int | mixed
Return type:float