@@ -52,75 +52,82 @@ def __repr__(self) -> str:
52
52
return 'FVal({})' .format (str (self .num ))
53
53
54
54
def __gt__ (self , other : AcceptableFValOtherInput ) -> bool :
55
- evaluated_other = evaluate_input (other )
55
+ evaluated_other = _evaluate_input (other )
56
56
return self .num .compare_signal (evaluated_other ) == Decimal ('1' )
57
57
58
58
def __lt__ (self , other : AcceptableFValOtherInput ) -> bool :
59
- evaluated_other = evaluate_input (other )
59
+ evaluated_other = _evaluate_input (other )
60
60
return self .num .compare_signal (evaluated_other ) == Decimal ('-1' )
61
61
62
62
def __le__ (self , other : AcceptableFValOtherInput ) -> bool :
63
- evaluated_other = evaluate_input (other )
63
+ evaluated_other = _evaluate_input (other )
64
64
return self .num .compare_signal (evaluated_other ) in (Decimal ('-1' ), Decimal ('0' ))
65
65
66
66
def __ge__ (self , other : AcceptableFValOtherInput ) -> bool :
67
- evaluated_other = evaluate_input (other )
67
+ evaluated_other = _evaluate_input (other )
68
68
return self .num .compare_signal (evaluated_other ) in (Decimal ('1' ), Decimal ('0' ))
69
69
70
70
def __eq__ (self , other : object ) -> bool :
71
- evaluated_other = evaluate_input (other )
71
+ evaluated_other : Union [Decimal , int ]
72
+ if isinstance (other , FVal ):
73
+ evaluated_other = other .num
74
+ elif not isinstance (other , int ):
75
+ return False
76
+ else :
77
+ evaluated_other = other
78
+
72
79
return self .num .compare_signal (evaluated_other ) == Decimal ('0' )
73
80
74
81
def __add__ (self , other : AcceptableFValOtherInput ) -> 'FVal' :
75
- evaluated_other = evaluate_input (other )
82
+ evaluated_other = _evaluate_input (other )
76
83
return FVal (self .num .__add__ (evaluated_other ))
77
84
78
85
def __sub__ (self , other : AcceptableFValOtherInput ) -> 'FVal' :
79
- evaluated_other = evaluate_input (other )
86
+ evaluated_other = _evaluate_input (other )
80
87
return FVal (self .num .__sub__ (evaluated_other ))
81
88
82
89
def __mul__ (self , other : AcceptableFValOtherInput ) -> 'FVal' :
83
- evaluated_other = evaluate_input (other )
90
+ evaluated_other = _evaluate_input (other )
84
91
return FVal (self .num .__mul__ (evaluated_other ))
85
92
86
93
def __truediv__ (self , other : AcceptableFValOtherInput ) -> 'FVal' :
87
- evaluated_other = evaluate_input (other )
94
+ evaluated_other = _evaluate_input (other )
88
95
return FVal (self .num .__truediv__ (evaluated_other ))
89
96
90
97
def __floordiv__ (self , other : AcceptableFValOtherInput ) -> 'FVal' :
91
- evaluated_other = evaluate_input (other )
98
+ evaluated_other = _evaluate_input (other )
92
99
return FVal (self .num .__floordiv__ (evaluated_other ))
93
100
94
101
def __pow__ (self , other : AcceptableFValOtherInput ) -> 'FVal' :
95
- evaluated_other = evaluate_input (other )
102
+ evaluated_other = _evaluate_input (other )
96
103
return FVal (self .num .__pow__ (evaluated_other ))
97
104
98
105
def __radd__ (self , other : AcceptableFValOtherInput ) -> 'FVal' :
99
- evaluated_other = evaluate_input (other )
106
+ evaluated_other = _evaluate_input (other )
100
107
return FVal (self .num .__radd__ (evaluated_other ))
101
108
102
109
def __rsub__ (self , other : AcceptableFValOtherInput ) -> 'FVal' :
103
- evaluated_other = evaluate_input (other )
110
+ evaluated_other = _evaluate_input (other )
104
111
return FVal (self .num .__rsub__ (evaluated_other ))
105
112
106
113
def __rmul__ (self , other : AcceptableFValOtherInput ) -> 'FVal' :
107
- evaluated_other = evaluate_input (other )
114
+ evaluated_other = _evaluate_input (other )
108
115
return FVal (self .num .__rmul__ (evaluated_other ))
109
116
110
117
def __rtruediv__ (self , other : AcceptableFValOtherInput ) -> 'FVal' :
111
- evaluated_other = evaluate_input (other )
118
+ evaluated_other = _evaluate_input (other )
112
119
return FVal (self .num .__rtruediv__ (evaluated_other ))
113
120
114
121
def __rfloordiv__ (self , other : AcceptableFValOtherInput ) -> 'FVal' :
115
- evaluated_other = evaluate_input (other )
122
+ evaluated_other = _evaluate_input (other )
116
123
return FVal (self .num .__rfloordiv__ (evaluated_other ))
117
124
118
125
def __mod__ (self , other : AcceptableFValOtherInput ) -> 'FVal' :
119
- evaluated_other = evaluate_input (other )
126
+ evaluated_other = _evaluate_input (other )
120
127
return FVal (self .num .__mod__ (evaluated_other ))
121
128
122
129
def __rmod__ (self , other : AcceptableFValOtherInput ) -> 'FVal' :
123
- evaluated_other = evaluate_input (other )
130
+ evaluated_other = _evaluate_input (other )
124
131
return FVal (self .num .__rmod__ (evaluated_other ))
125
132
126
133
def __float__ (self ) -> float :
@@ -141,8 +148,8 @@ def fma(self, other: AcceptableFValOtherInput, third: AcceptableFValOtherInput)
141
148
Fused multiply-add. Return self*other+third with no rounding of the
142
149
intermediate product self*other
143
150
"""
144
- evaluated_other = evaluate_input (other )
145
- evaluated_third = evaluate_input (third )
151
+ evaluated_other = _evaluate_input (other )
152
+ evaluated_third = _evaluate_input (third )
146
153
return FVal (self .num .fma (evaluated_other , evaluated_third ))
147
154
148
155
def to_percentage (self , precision : int = 4 , with_perc_sign : bool = True ) -> str :
@@ -170,7 +177,7 @@ def is_close(self, other: AcceptableFValInitInput, max_diff: str = "1e-6") -> bo
170
177
return diff_num <= evaluated_max_diff .num
171
178
172
179
173
- def evaluate_input (other : Any ) -> Union [Decimal , int ]:
180
+ def _evaluate_input (other : Any ) -> Union [Decimal , int ]:
174
181
"""Evaluate 'other' and return its Decimal representation"""
175
182
if isinstance (other , FVal ):
176
183
return other .num
0 commit comments