highPrecision.py 954 Bytes
from decimal import *


PRECISION = Decimal(0.0000000001)

'''
    Compare the two decimal, according to the given precision
'''


def is_nearby_equal(a: Decimal, b: Decimal, precision=PRECISION):
    return (True if abs(b - a) < precision else False)


'''
    Compare the two decimal, according to the given precision
'''


def is_nearby_sup_or_equal(a: Decimal, b: Decimal, precision=PRECISION):
    if (a > b):
        return True
    return (True if abs(b - a) < precision else False)


'''
    Compare the two decimal, according to the given precision
'''


def is_nearby_less_or_equal(a: Decimal, b: Decimal, precision=PRECISION):
    if (a < b):
        return True
    return (True if abs(b - a) < precision else False)


'''
    Check if decimal is between
'''


def is_between(a: Decimal, b: Decimal, c: Decimal, precision=PRECISION):
    if is_nearby_less_or_equal(a, b) and is_nearby_less_or_equal(b, c):
        return True
    return False