]> gcc.gnu.org Git - gcc.git/commitdiff
sreal.h (to_double): New method.
authorJan Hubicka <hubicka@ucw.cz>
Mon, 15 Dec 2014 22:03:11 +0000 (23:03 +0100)
committerJan Hubicka <hubicka@gcc.gnu.org>
Mon, 15 Dec 2014 22:03:11 +0000 (22:03 +0000)
* sreal.h (to_double): New method.
(shift): Do not ICE on 0.
* sreal.c: Include math.h
(sreal::to_double): New.

From-SVN: r218765

gcc/ChangeLog
gcc/sreal.c
gcc/sreal.h

index 07aa48c4ba5dc11dd382e1f3510d46edbb5ec4b0..e050f0327574e1b47c8aed18eb5ce5334efadd52 100644 (file)
@@ -1,3 +1,10 @@
+2014-12-15  Jan Hubicka  <hubicka@ucw.cz>
+
+       * sreal.h (to_double): New method.
+       (shift): Do not ICE on 0.
+       * sreal.c: Include math.h
+       (sreal::to_double): New.
+
 2014-12-15  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/64316
index bc3af2309db4554483c34989c1c7442983ddcbe2..10de80b770217582cc2b43ce904cd4af55187a34 100644 (file)
@@ -47,6 +47,7 @@ along with GCC; see the file COPYING3.  If not see
        sig == 0 && exp == -SREAL_MAX_EXP
 */
 
+#include <math.h>
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
@@ -171,6 +172,18 @@ sreal::to_int () const
   return m_sig;
 }
 
+/* Return value of *this as double.
+   This should be used for debug output only.  */
+
+double
+sreal::to_double () const
+{
+  double val = m_sig;
+  if (m_exp)
+    val *= exp2 (m_exp);
+  return val;
+}
+
 /* Return *this + other.  */
 
 sreal
index 730f49c4d899a97c944e452ee489ae2303e8c1e9..6314cea0fc488d38c620b1632216eed9b9f3f68c 100644 (file)
@@ -46,6 +46,7 @@ public:
 
   void dump (FILE *) const;
   int64_t to_int () const;
+  double to_double () const;
   sreal operator+ (const sreal &other) const;
   sreal operator- (const sreal &other) const;
   sreal operator* (const sreal &other) const;
@@ -83,12 +84,14 @@ public:
 
   sreal shift (int s) const
   {
+    /* Zero needs no shifting.  */
+    if (!m_sig)
+      return *this;
     gcc_checking_assert (s <= SREAL_BITS);
     gcc_checking_assert (s >= -SREAL_BITS);
 
-    /* Exponent should never be so large because shift_right is used only by
-     sreal_add and sreal_sub ant thus the number cannot be shifted out from
-     exponent range.  */
+    /* Overflows/drop to 0 could be handled gracefully, but hopefully we do not
+       need to do so.  */
     gcc_checking_assert (m_exp + s <= SREAL_MAX_EXP);
     gcc_checking_assert (m_exp + s >= -SREAL_MAX_EXP);
 
This page took 0.321909 seconds and 5 git commands to generate.