add fp value to BFPState.__repr__
authorJacob Lifshay <programmerjake@gmail.com>
Wed, 17 May 2023 04:50:47 +0000 (21:50 -0700)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 2 Jun 2023 18:51:18 +0000 (19:51 +0100)
src/openpower/decoder/fp_working_format.py

index b1fdf56c9d9a0c1275b235b373dde4d39b49d0fd..0dfc9bbabd2c698fc943ec23dbd57d541810427c 100644 (file)
@@ -436,9 +436,26 @@ class BFPState:
                 f"significand: {self.significand}",
                 *self.class_._bfp_state_fields())
 
+    def __str__(self):
+        if self.class_.SNaN:
+            return "SNaN"
+        if self.class_.QNaN:
+            return "QNaN"
+        if self.class_.Infinity:
+            return "-Inf" if self.sign else "Inf"
+        retval = self.significand
+        if self.sign:
+            retval = -retval
+        retval <<= self.exponent
+        sign = ""
+        if retval < 0:
+            sign = "-"
+            retval = -retval
+        return sign + retval.__str__(max_int_digits=16)
+
     def __repr__(self):
         fields = self._bfp_state_fields()
-        return f"<BFPState {fields}>"
+        return f"<BFPState {self} {fields}>"
 
 
 # TODO: add tests