Blame view

src/utils/highPrecision.py 954 Bytes
bca9a283   Jeremy   Reworked the sche...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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