otp.Operation.decimal.cmp#

cmp(other, eps)#

Compare two decimal values according to eps relative difference.

This function returns 0 if column = other, 1 if column > other, and -1 if column < other. Two numbers are considered to be equal if both of them are NaN or abs(column - other) / (abs(column) + abs(other)) < eps. In other words, eps represents a relative difference (percentage) between the two numbers, not an absolute difference.

Parameters
Returns

result – 0 if column == other, 1 if column > other, and -1 if column < other.

Return type

Operation

Examples

>>> data = otp.Ticks(
...     X=[otp.decimal(1), otp.decimal(2.17), otp.decimal(10.31841), otp.decimal(3.141593), otp.decimal(6)],
...     OTHER=[otp.decimal(1.01), otp.decimal(2.1), otp.decimal(10.32841), otp.decimal(3.14), otp.decimal(5)],
...     EPS=[0, 1, 0.1, 0.001, 0.001]
... )
>>> data['X'] = data['X'].decimal.cmp(data['OTHER'], data['EPS'])
>>> data = otp.run(data)
>>> data['X']
0   -1.0
1    0.0
2    0.0
3    0.0
4    1.0
Name: X, dtype: float64