37 using Storage = std::variant<std::monostate, R2, R3, R4, R8, R10, R16>;
41 ~RealValueImpl() =
default;
42 RealValueImpl(
const RealValueImpl &) =
default;
43 RealValueImpl(RealValueImpl &&) =
default;
44 RealValueImpl &operator=(
const RealValueImpl &) =
default;
45 RealValueImpl &operator=(RealValueImpl &&) =
default;
47 RealValueImpl() =
default;
50 RealValueImpl(
int kind,
const Word &w);
52 RealValueImpl(
int kind,
double x);
54 static RealValueImpl Zero(
int kind);
56 template <
typename T>
static RealValueImpl FromWord(
const T &r) {
66 r.value = FromWord(x.value);
71 static RealValueImpl FromRawBytes(
72 int kind,
const void *raw, std::size_t expectedSize);
74 void print(llvm::raw_ostream &os)
const;
76#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
77 LLVM_DUMP_METHOD
void dump()
const;
80 bool IsNull()
const {
return storage_.index() == 0; }
85 std::size_t bytesStored()
const {
return bytesStored(kind()); }
86 static constexpr std::size_t bytesStored(
int kind) {
100 bool operator==(
const RealValueImpl &y)
const;
101 bool operator!=(
const RealValueImpl &y)
const {
return !(*
this == y); }
105 static int DIGITS(
int kind);
106 static int PRECISION(
int kind);
107 static int RANGE(
int kind);
108 static int MAXEXPONENT(
int kind);
109 static int MINEXPONENT(
int kind);
111 static RealValueImpl HUGE(
int kind);
112 static RealValueImpl EPSILON(
int kind);
113 static RealValueImpl TINY(
int kind);
114 static RealValueImpl NotANumber(
int kind);
115 static RealValueImpl Infinity(
int kind,
bool negative =
false);
116 static RealValueImpl NegativeZero(
int kind);
119 bool IsNegative()
const;
120 bool IsNotANumber()
const;
121 bool IsSignalingNaN()
const;
122 bool IsInfinite()
const;
123 bool IsFinite()
const;
124 bool IsNormal()
const;
125 int Exponent()
const;
126 void StoreRawBytes(
void *dst,
size_t size,
bool *changed)
const;
132 Relation Compare(
const RealValueImpl &y)
const;
135 RealValueImpl ABS()
const;
136 RealValueImpl Negate()
const;
137 RealValueImpl SIGN(
const RealValueImpl &x)
const;
138 RealValueImpl SetSign(
bool toNegative)
const;
139 RealValueImpl FlushSubnormalToZero()
const;
143 Rounding rounding = TargetCharacteristics::defaultRounding)
const;
145 Rounding rounding = TargetCharacteristics::defaultRounding)
const;
147 Rounding rounding = TargetCharacteristics::defaultRounding)
const;
149 Rounding rounding = TargetCharacteristics::defaultRounding)
const;
151 Rounding rounding = TargetCharacteristics::defaultRounding)
const;
153 Rounding rounding = TargetCharacteristics::defaultRounding)
const;
155 Rounding rounding = TargetCharacteristics::defaultRounding)
const;
157 Rounding rounding = TargetCharacteristics::defaultRounding)
const;
159 Rounding rounding = TargetCharacteristics::defaultRounding)
const;
161 RealValueImpl FRACTION()
const;
162 RealValueImpl RRSPACING()
const;
163 RealValueImpl SPACING()
const;
164 RealValueImpl SET_EXPONENT(std::int64_t e)
const;
168 common::RoundingMode mode = common::RoundingMode::ToZero)
const;
171 common::RoundingMode mode = common::RoundingMode::ToZero,
172 int toBits = 0)
const;
175 Rounding rounding = TargetCharacteristics::defaultRounding)
const;
178 RealValueImpl &correction,
179 Rounding rounding = TargetCharacteristics::defaultRounding)
const;
186 Rounding rounding = TargetCharacteristics::defaultRounding);
190 const RealValueImpl &from,
191 Rounding rounding = TargetCharacteristics::defaultRounding);
194 Rounding rounding = TargetCharacteristics::defaultRounding);
196 std::string DumpHexadecimal()
const;
197 llvm::raw_ostream &AsFortran(
198 llvm::raw_ostream &o,
int kind,
bool minimal =
false)
const;
214 if (!std::holds_alternative<T>(storage_)) {
215 DIE(
"value does not store the requested kind");
218 return std::get<T>(storage_);
221 template <
typename F>
static inline auto WithWordProto(
int kind, F &&f) {
222 using namespace Fortran::evaluate::value;
225 return f(RealValueImpl::R2{});
227 return f(RealValueImpl::R3{});
229 return f(RealValueImpl::R4{});
231 return f(RealValueImpl::R8{});
233 return f(RealValueImpl::R10{});
235 return f(RealValueImpl::R16{});
237 DIE(
"arbitrary bits not yet supported");
241 template <
typename F>
auto WithWord(F &&f)
const {
242 switch (storage_.index()) {
244 return f(std::get<1>(storage_));
246 return f(std::get<2>(storage_));
248 return f(std::get<3>(storage_));
250 return f(std::get<4>(storage_));
252 return f(std::get<5>(storage_));
254 return f(std::get<6>(storage_));
256 DIE(
"operation on uninitialized RealValueImpl");