ceil_round_down

ketos.utils.ceil_round_down(a, decimals=6)[source]

Provides a convenient way to use ceil while specifying a decimal precision to floor instead This helps deal with imprecision of finite number of floating points arithmetics

For instance: 2.8/0.2 can be displayed as 14.00000000001 instead of 14. And this leads to np.ceil(2.8/0.2) == 15

With this function we can specify a decimal point to round down values that are very close to the previous integer. For instance with the default decimals=6, any number with decimals equal or smaller than .000001 is rounded down to the previous integer otherwise ceil is used.

ceil_round_down(13.000001, decimals=6) == 13 while ceil_round_down(13.0000011, decimals=6) == 14`

More examples below.

Args:
a: array_like

Input data.

decimals: int

Decimal places. decimals == 0 is the same as np.ceil()

Returns
: ndarray or scalar

The ceil of each element in x. This is a scalar if x is a scalar. Floor is used depending on decimals

Example:
>>> from ketos.utils import ceil_round_down
>>> ceil_round_down(13.000001, decimals=6)
13.0
>>> ceil_round_down(13.0000011, decimals=6)
14.0
>>> ceil_round_down(13.0000010000001, decimals=6)
14.0
>>> ceil_round_down(13.00000000001, decimals=0)
14.0
>>> ceil_round_down(13.1, decimals=1)
13.0
>>> ceil_round_down(13.10000001, decimals=1)
14.0