Merge branch 'master' r217593-r217725 into gimple-classes-v2-option-3
[official-gcc.git] / gcc / sreal.h
blob461e28b3d2698bd47d890dc2348db0c76eb2f5de
1 /* Definitions for simple data type for positive real numbers.
2 Copyright (C) 2002-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_SREAL_H
21 #define GCC_SREAL_H
23 /* SREAL_PART_BITS has to be an even number. */
24 #define SREAL_PART_BITS 32
26 #define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 1))
27 #define SREAL_MAX_SIG (((uint64_t) 1 << SREAL_PART_BITS) - 1)
28 #define SREAL_MAX_EXP (INT_MAX / 4)
30 #define SREAL_BITS SREAL_PART_BITS
32 /* Structure for holding a simple real number. */
33 class sreal
35 public:
36 /* Construct an uninitialized sreal. */
37 sreal () : m_sig (-1), m_exp (-1) {}
39 /* Construct a sreal. */
40 sreal (uint64_t sig, int exp) : m_sig (sig), m_exp (exp) { normalize (); }
42 void dump (FILE *) const;
43 int64_t to_int () const;
45 sreal operator+ (const sreal &other) const;
46 sreal operator- (const sreal &other) const;
47 sreal operator* (const sreal &other) const;
48 sreal operator/ (const sreal &other) const;
50 bool operator< (const sreal &other) const
52 return m_exp < other.m_exp
53 || (m_exp == other.m_exp && m_sig < other.m_sig);
56 bool operator== (const sreal &other) const
58 return m_exp == other.m_exp && m_sig == other.m_sig;
61 private:
62 void normalize ();
63 void shift_right (int amount);
65 uint64_t m_sig; /* Significant. */
66 signed int m_exp; /* Exponent. */
69 extern void debug (sreal &ref);
70 extern void debug (sreal *ptr);
72 inline sreal &operator+= (sreal &a, const sreal &b)
74 return a = a + b;
77 inline sreal &operator-= (sreal &a, const sreal &b)
79 return a = a - b;
82 inline sreal &operator/= (sreal &a, const sreal &b)
84 return a = a / b;
87 inline sreal &operator*= (sreal &a, const sreal &b)
89 return a = a * b;
92 inline bool operator!= (const sreal &a, const sreal &b)
94 return !(a == b);
97 inline bool operator> (const sreal &a, const sreal &b)
99 return !(a == b || a < b);
102 inline bool operator<= (const sreal &a, const sreal &b)
104 return a < b || a == b;
107 inline bool operator>= (const sreal &a, const sreal &b)
109 return a == b || a > b;
112 #endif