1 /* longdouble.h -- Definitions of floating-point access for the frontend.
2 Copyright (C) 2015-2018 Free Software Foundation, Inc.
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)
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.
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/>. */
18 #ifndef GCC_D_LONGDOUBLE_H
19 #define GCC_D_LONGDOUBLE_H
27 /* Return the hidden real_value from the longdouble type. */
28 const real_value
& rv (void) const
29 { return *(const real_value
*) this; }
32 { return *(real_value
*) this; }
34 /* Normalize the value to be the precision supported by target. */
35 longdouble
normalize (void);
37 /* No constructor to be able to use this class in a union. */
38 template<typename T
> longdouble
& operator = (T x
)
39 { set (x
); return *this; }
41 /* Lvalue operators. */
42 void set (real_value
& d
);
45 void set (uint32_t d
);
46 void set (uint64_t d
);
49 /* Rvalue operators. */
50 bool to_bool () const;
51 int64_t to_int () const;
52 uint64_t to_uint () const;
54 operator int32_t (void)
55 { return (int32_t) this->to_int (); }
57 operator int64_t (void)
58 { return this->to_int (); }
60 operator uint32_t (void)
61 { return (uint32_t) this->to_uint (); }
63 operator uint64_t (void)
64 { return this->to_uint (); }
67 { return this->to_bool (); }
69 /* Arithmetic operators. */
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;
75 longdouble
neg () const;
77 longdouble
operator + (const longdouble
& r
)
78 { return this->add (r
); }
80 longdouble
operator - (const longdouble
& r
)
81 { return this->sub (r
); }
83 longdouble
operator * (const longdouble
& r
)
84 { return this->mul (r
); }
86 longdouble
operator / (const longdouble
& r
)
87 { return this->div (r
); }
89 longdouble
operator % (const longdouble
& r
)
90 { return this->mod (r
); }
92 longdouble
operator -()
93 { return this->neg (); }
95 /* Comparison operators. */
96 int cmp (const longdouble
& t
) const;
97 int equals (const longdouble
& t
) const;
99 bool operator < (const longdouble
& r
)
100 { return this->cmp (r
) < 0; }
102 bool operator <= (const longdouble
& r
)
103 { return this->cmp (r
) <= 0; }
105 bool operator > (const longdouble
& r
)
106 { return this->cmp (r
) > 0; }
108 bool operator >= (const longdouble
& r
)
109 { return this->cmp (r
) >= 0; }
111 bool operator == (const longdouble
& r
)
112 { return this->equals (r
); }
114 bool operator != (const longdouble
& r
)
115 { return !this->equals (r
); }
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))];
123 /* Declared, but "volatile" is not required. */
124 typedef longdouble volatile_longdouble
;
126 /* Use ldouble() to explicitly create a longdouble value. */
136 #endif /* GCC_D_LONGDOUBLE_H */