@@ -75,6 +75,7 @@ def __init__(
75
75
self .original_number : Decimal = self .number
76
76
if self .__edge_case is None :
77
77
self .sign : str = self .find_sign ()
78
+ self .number = self .number .copy_abs ()
78
79
self .__scale , self .number = self .scale_up_to_integer (self .number , 2 )
79
80
self .binary : str = f"{ self .number :b} "
80
81
self .binary_output : str = (
@@ -171,12 +172,12 @@ def find_sign(self) -> str:
171
172
return "1"
172
173
return "0"
173
174
174
- @staticmethod
175
- def scale_up_to_integer (number : Decimal , base : int ) -> (int , int ):
175
+ def scale_up_to_integer (self , number : Decimal , base : int ) -> (int , int ):
176
176
scale = 0
177
177
while number != int (number ):
178
178
number *= base
179
179
scale += 1
180
+ self .output ["unable_to_scale" ] = scale > 100
180
181
return scale , int (number )
181
182
182
183
def find_exponent (self ) -> str :
@@ -449,5 +450,13 @@ def octuple(x: str) -> IEEE754:
449
450
x = 8.7
450
451
a = IEEE754 (x , 1 )
451
452
print (f"{ x } is converted as { a .converted_number } ± { a .error } " )
452
- # you can get the full output as a dictionary with produce_output()
453
- print (a .produce_output ())
453
+ x = - 0.75
454
+ a = IEEE754 (x , 1 )
455
+ print (f"{ x } is converted as { a .converted_number } ± { a .error } " )
456
+ # test edge cases
457
+ print (IEEE754 (0 ))
458
+ print (IEEE754 ("-0" ))
459
+ print (IEEE754 ("Infinity" ))
460
+ print (IEEE754 ("-Infinity" ))
461
+ print (IEEE754 ("NaN" ))
462
+ print (IEEE754 ("-NaN" ))
0 commit comments