Commit 2bef63e1 by Jan Hubicka Committed by Jan Hubicka

sreal.h (to_double): New method.


	* sreal.h (to_double): New method.
	(shift): Do not ICE on 0.
	* sreal.c: Include math.h
	(sreal::to_double): New.

From-SVN: r218765
parent 426bcc95
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> 2014-12-15 Jakub Jelinek <jakub@redhat.com>
PR rtl-optimization/64316 PR rtl-optimization/64316
...@@ -47,6 +47,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -47,6 +47,7 @@ along with GCC; see the file COPYING3. If not see
sig == 0 && exp == -SREAL_MAX_EXP sig == 0 && exp == -SREAL_MAX_EXP
*/ */
#include <math.h>
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "coretypes.h" #include "coretypes.h"
...@@ -171,6 +172,18 @@ sreal::to_int () const ...@@ -171,6 +172,18 @@ sreal::to_int () const
return m_sig; 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. */ /* Return *this + other. */
sreal sreal
......
...@@ -46,6 +46,7 @@ public: ...@@ -46,6 +46,7 @@ public:
void dump (FILE *) const; void dump (FILE *) const;
int64_t to_int () 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; sreal operator- (const sreal &other) const;
sreal operator* (const sreal &other) const; sreal operator* (const sreal &other) const;
...@@ -83,12 +84,14 @@ public: ...@@ -83,12 +84,14 @@ public:
sreal shift (int s) const 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);
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 /* Overflows/drop to 0 could be handled gracefully, but hopefully we do not
sreal_add and sreal_sub ant thus the number cannot be shifted out from need to do so. */
exponent range. */
gcc_checking_assert (m_exp + s <= SREAL_MAX_EXP); gcc_checking_assert (m_exp + s <= SREAL_MAX_EXP);
gcc_checking_assert (m_exp + s >= -SREAL_MAX_EXP); gcc_checking_assert (m_exp + s >= -SREAL_MAX_EXP);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment