]>
Commit | Line | Data |
---|---|---|
b4c522fa | 1 | /* longdouble.h -- Definitions of floating-point access for the frontend. |
83ffe9cd | 2 | Copyright (C) 2015-2023 Free Software Foundation, Inc. |
b4c522fa IB |
3 | |
4 | GCC is free software; you can redistribute it and/or modify | |
5 | it under the terms of the GNU General Public License as published by | |
6 | the Free Software Foundation; either version 3, or (at your option) | |
7 | any later version. | |
8 | ||
9 | GCC is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along with GCC; see the file COPYING3. If not see | |
16 | <http://www.gnu.org/licenses/>. */ | |
17 | ||
18 | #ifndef GCC_D_LONGDOUBLE_H | |
19 | #define GCC_D_LONGDOUBLE_H | |
20 | ||
21 | struct real_value; | |
22 | class Type; | |
23 | ||
24 | struct longdouble | |
25 | { | |
26 | public: | |
27 | /* Return the hidden real_value from the longdouble type. */ | |
af3c19f0 | 28 | const real_value &rv (void) const |
b4c522fa IB |
29 | { return *(const real_value *) this; } |
30 | ||
af3c19f0 | 31 | real_value &rv (void) |
b4c522fa IB |
32 | { return *(real_value *) this; } |
33 | ||
34 | /* Normalize the value to be the precision supported by target. */ | |
35 | longdouble normalize (void); | |
36 | ||
37 | /* No constructor to be able to use this class in a union. */ | |
af3c19f0 | 38 | template <typename T> longdouble &operator = (T x) |
b4c522fa IB |
39 | { set (x); return *this; } |
40 | ||
41 | /* Lvalue operators. */ | |
af3c19f0 | 42 | void set (real_value &d); |
b4c522fa IB |
43 | void set (int32_t d); |
44 | void set (int64_t d); | |
45 | void set (uint32_t d); | |
46 | void set (uint64_t d); | |
47 | void set (bool d); | |
48 | ||
49 | /* Rvalue operators. */ | |
50 | bool to_bool () const; | |
51 | int64_t to_int () const; | |
52 | uint64_t to_uint () const; | |
53 | ||
54 | operator int32_t (void) | |
55 | { return (int32_t) this->to_int (); } | |
56 | ||
57 | operator int64_t (void) | |
58 | { return this->to_int (); } | |
59 | ||
60 | operator uint32_t (void) | |
61 | { return (uint32_t) this->to_uint (); } | |
62 | ||
63 | operator uint64_t (void) | |
64 | { return this->to_uint (); } | |
65 | ||
66 | operator bool (void) | |
67 | { return this->to_bool (); } | |
68 | ||
69 | /* Arithmetic operators. */ | |
af3c19f0 IB |
70 | longdouble add (const longdouble &r) const; |
71 | longdouble sub (const longdouble &r) const; | |
72 | longdouble mul (const longdouble &r) const; | |
73 | longdouble div (const longdouble &r) const; | |
74 | longdouble mod (const longdouble &r) const; | |
b4c522fa IB |
75 | longdouble neg () const; |
76 | ||
af3c19f0 | 77 | longdouble operator + (const longdouble &r) |
b4c522fa IB |
78 | { return this->add (r); } |
79 | ||
af3c19f0 | 80 | longdouble operator - (const longdouble &r) |
b4c522fa IB |
81 | { return this->sub (r); } |
82 | ||
af3c19f0 | 83 | longdouble operator * (const longdouble &r) |
b4c522fa IB |
84 | { return this->mul (r); } |
85 | ||
af3c19f0 | 86 | longdouble operator / (const longdouble &r) |
b4c522fa IB |
87 | { return this->div (r); } |
88 | ||
af3c19f0 | 89 | longdouble operator % (const longdouble &r) |
b4c522fa IB |
90 | { return this->mod (r); } |
91 | ||
af3c19f0 | 92 | longdouble operator - (void) |
b4c522fa IB |
93 | { return this->neg (); } |
94 | ||
95 | /* Comparison operators. */ | |
af3c19f0 IB |
96 | int cmp (const longdouble &t) const; |
97 | int equals (const longdouble &t) const; | |
b4c522fa | 98 | |
af3c19f0 | 99 | bool operator < (const longdouble &r) |
b4c522fa IB |
100 | { return this->cmp (r) < 0; } |
101 | ||
af3c19f0 | 102 | bool operator <= (const longdouble &r) |
b4c522fa IB |
103 | { return this->cmp (r) <= 0; } |
104 | ||
af3c19f0 | 105 | bool operator > (const longdouble &r) |
b4c522fa IB |
106 | { return this->cmp (r) > 0; } |
107 | ||
af3c19f0 | 108 | bool operator >= (const longdouble &r) |
b4c522fa IB |
109 | { return this->cmp (r) >= 0; } |
110 | ||
af3c19f0 | 111 | bool operator == (const longdouble &r) |
b4c522fa IB |
112 | { return this->equals (r); } |
113 | ||
af3c19f0 | 114 | bool operator != (const longdouble &r) |
b4c522fa IB |
115 | { return !this->equals (r); } |
116 | ||
117 | private: | |
118 | /* Including gcc/real.h presents too many problems, so just | |
119 | statically allocate enough space for REAL_VALUE_TYPE. */ | |
120 | long realvalue[(2 + (16 + sizeof (long)) / sizeof (long))]; | |
121 | }; | |
122 | ||
123 | /* Declared, but "volatile" is not required. */ | |
124 | typedef longdouble volatile_longdouble; | |
125 | ||
126 | /* Use ldouble() to explicitly create a longdouble value. */ | |
af3c19f0 | 127 | template <typename T> |
b4c522fa IB |
128 | inline longdouble |
129 | ldouble (T x) | |
130 | { | |
131 | longdouble d; | |
132 | d.set (x); | |
133 | return d; | |
134 | } | |
135 | ||
136 | #endif /* GCC_D_LONGDOUBLE_H */ |