Skip to content

Commit 1e97c15

Browse files
committed
output for convert back to decimal
1 parent e13ce84 commit 1e97c15

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ieee754/IEEE754.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ def __init__(
6161
"scaled_number_in_binary": "",
6262
"unable_to_scale": False,
6363
"bias": "",
64+
"bias_in_binary": "",
6465
"exponent": "",
6566
"mantissa": "",
67+
"mantissa_base_10": "",
6668
"result": "",
6769
"hexadecimal": "",
6870
"hexadecimal_parts": [],
@@ -229,6 +231,7 @@ def produce_output(self) -> dict:
229231
self.output["exponent"] = self.exponent
230232
self.output["mantissa"] = self.mantissa
231233
self.output["bias"] = self.__bias
234+
self.output["bias_in_binary"] = f"{self.__bias:0{self.__exponent}b}"
232235
self.output["hexadecimal"], self.output["hexadecimal_parts"] = self.hex()
233236
self.output["result"] = self.__str__()
234237
if self.__edge_case is None:
@@ -251,6 +254,10 @@ def back_to_decimal_from_bits(self) -> (Decimal, Decimal):
251254
Decimal representation of the number
252255
"""
253256
sign, exponent, mantissa = self.__str__().split(" ")
257+
mantissa_base_10 = Decimal(0)
258+
for i in range(len(mantissa)):
259+
mantissa_base_10 += Decimal(int(mantissa[i]) * Decimal(2) ** -(i + 1))
260+
self.output["mantissa_base_10"] = mantissa_base_10
254261
sign = (-1) ** int(sign)
255262
exponent = int(exponent, 2) - self.__bias
256263
mantissa = int(mantissa, 2)
@@ -460,3 +467,4 @@ def octuple(x: str) -> IEEE754:
460467
print(IEEE754("-Infinity"))
461468
print(IEEE754("NaN"))
462469
print(IEEE754("-NaN"))
470+
print(half(-0.17))

0 commit comments

Comments
 (0)