floor_round_up

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

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

For instance: 2.8/0.2 can be displayed as 13.99999999998 instead of 14. And this leads to np.floor(2.8/0.2) == 13

With this function we can specify a decimal point to round up values that are very close to the next integer. For instance with the default decimals=6, any number with decimals equal or bigger than .999999 is rounded up to the next integer otherwise floor is used.

floor_round_up(13.999999, decimals=6) == 14 while floor_round_up(13.999998, decimals=6) == 13`

More examples below.

Args:
a: array_like

Input data.

decimals: int

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

Returns
: ndarray or scalar

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

Example:
>>> from ketos.utils import floor_round_up
>>> floor_round_up(13.999998, decimals=6)
13.0
>>> floor_round_up(13.999999, decimals=6)
14.0
>>> floor_round_up(13.9999989999, decimals=6)
13.0
>>> floor_round_up(13.9999998, decimals=0)
13.0
>>> floor_round_up(13.9, decimals=1)
14.0
>>> floor_round_up(13.8999999, decimals=1)
13.0