LLVM 23.0.0git
APFloat.h
Go to the documentation of this file.
1//===- llvm/ADT/APFloat.h - Arbitrary Precision Floating Point ---*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file declares a class to represent arbitrary precision floating point
11/// values and provide a variety of arithmetic operations on them.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_ADT_APFLOAT_H
16#define LLVM_ADT_APFLOAT_H
17
18#include "llvm/ADT/APInt.h"
19#include "llvm/ADT/ArrayRef.h"
24#include <memory>
25#include <optional>
26
27#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL) \
28 do { \
29 if (usesLayout<IEEEFloat>(getSemantics())) \
30 return U.IEEE.METHOD_CALL; \
31 if (usesLayout<DoubleAPFloat>(getSemantics())) \
32 return U.Double.METHOD_CALL; \
33 llvm_unreachable("Unexpected semantics"); \
34 } while (false)
35
36namespace llvm {
37
38struct fltSemantics;
39class APSInt;
40class StringRef;
41class APFloat;
42class raw_ostream;
43
44template <typename T> class Expected;
45template <typename T> class SmallVectorImpl;
46
47/// Enum that represents what fraction of the LSB truncated bits of an fp number
48/// represent.
49///
50/// This essentially combines the roles of guard and sticky bits.
51enum lostFraction { // Example of truncated bits:
52 lfExactlyZero, // 000000
53 lfLessThanHalf, // 0xxxxx x's not all zero
54 lfExactlyHalf, // 100000
55 lfMoreThanHalf // 1xxxxx x's not all zero
56};
57
58/// A self-contained host- and target-independent arbitrary-precision
59/// floating-point software implementation.
60///
61/// APFloat uses bignum integer arithmetic as provided by static functions in
62/// the APInt class. The library will work with bignum integers whose parts are
63/// any unsigned type at least 16 bits wide, but 64 bits is recommended.
64///
65/// Written for clarity rather than speed, in particular with a view to use in
66/// the front-end of a cross compiler so that target arithmetic can be correctly
67/// performed on the host. Performance should nonetheless be reasonable,
68/// particularly for its intended use. It may be useful as a base
69/// implementation for a run-time library during development of a faster
70/// target-specific one.
71///
72/// All 5 rounding modes in the IEEE-754R draft are handled correctly for all
73/// implemented operations. Currently implemented operations are add, subtract,
74/// multiply, divide, fused-multiply-add, conversion-to-float,
75/// conversion-to-integer and conversion-from-integer. New rounding modes
76/// (e.g. away from zero) can be added with three or four lines of code.
77///
78/// Four formats are built-in: IEEE single precision, double precision,
79/// quadruple precision, and x87 80-bit extended double (when operating with
80/// full extended precision). Adding a new format that obeys IEEE semantics
81/// only requires adding two lines of code: a declaration and definition of the
82/// format.
83///
84/// All operations return the status of that operation as an exception bit-mask,
85/// so multiple operations can be done consecutively with their results or-ed
86/// together. The returned status can be useful for compiler diagnostics; e.g.,
87/// inexact, underflow and overflow can be easily diagnosed on constant folding,
88/// and compiler optimizers can determine what exceptions would be raised by
89/// folding operations and optimize, or perhaps not optimize, accordingly.
90///
91/// At present, underflow tininess is detected after rounding; it should be
92/// straight forward to add support for the before-rounding case too.
93///
94/// The library reads hexadecimal floating point numbers as per C99, and
95/// correctly rounds if necessary according to the specified rounding mode.
96/// Syntax is required to have been validated by the caller. It also converts
97/// floating point numbers to hexadecimal text as per the C99 %a and %A
98/// conversions. The output precision (or alternatively the natural minimal
99/// precision) can be specified; if the requested precision is less than the
100/// natural precision the output is correctly rounded for the specified rounding
101/// mode.
102///
103/// It also reads decimal floating point numbers and correctly rounds according
104/// to the specified rounding mode.
105///
106/// Conversion to decimal text is not currently implemented.
107///
108/// Non-zero finite numbers are represented internally as a sign bit, a 16-bit
109/// signed exponent, and the significand as an array of integer parts. After
110/// normalization of a number of precision P the exponent is within the range of
111/// the format, and if the number is not denormal the P-th bit of the
112/// significand is set as an explicit integer bit. For denormals the most
113/// significant bit is shifted right so that the exponent is maintained at the
114/// format's minimum, so that the smallest denormal has just the least
115/// significant bit of the significand set. The sign of zeroes and infinities
116/// is significant; the exponent and significand of such numbers is not stored,
117/// but has a known implicit (deterministic) value: 0 for the significands, 0
118/// for zero exponent, all 1 bits for infinity exponent. For NaNs the sign and
119/// significand are deterministic, although not really meaningful, and preserved
120/// in non-conversion operations. The exponent is implicitly all 1 bits.
121///
122/// APFloat does not provide any exception handling beyond default exception
123/// handling. We represent Signaling NaNs via IEEE-754R 2008 6.2.1 should clause
124/// by encoding Signaling NaNs with the first bit of its trailing significand as
125/// 0.
126///
127/// TODO
128/// ====
129///
130/// Some features that may or may not be worth adding:
131///
132/// Binary to decimal conversion (hard).
133///
134/// Optional ability to detect underflow tininess before rounding.
135///
136/// New formats: x87 in single and double precision mode (IEEE apart from
137/// extended exponent range) (hard).
138///
139/// New operations: sqrt, IEEE remainder, C90 fmod, nexttoward.
140///
141
142namespace detail {
143class IEEEFloat;
144class DoubleAPFloat;
145} // namespace detail
146
147// This is the common type definitions shared by APFloat and its internal
148// implementation classes. This struct should not define any non-static data
149// members.
151public:
153 static constexpr unsigned integerPartWidth = APInt::APINT_BITS_PER_WORD;
154
155 /// A signed type to represent a floating point numbers unbiased exponent.
156 using ExponentType = int32_t;
157
158 /// \name Floating Point Semantics.
159 /// @{
166 // The IBM double-double semantics. Such a number consists of a pair of
167 // IEEE 64-bit doubles (Hi, Lo), where |Hi| > |Lo|, and if normal,
168 // (double)(Hi + Lo) == Hi. The numeric value it's modeling is Hi + Lo.
169 // Therefore it has two 53-bit mantissa parts that aren't necessarily
170 // adjacent to each other, and two 11-bit exponents.
171 //
172 // Note: we need to make the value different from semBogus as otherwise
173 // an unsafe optimization may collapse both values to a single address,
174 // and we heavily rely on them having distinct addresses.
176 // These are legacy semantics for the fallback, inaccurate implementation
177 // of IBM double-double, if the accurate semPPCDoubleDouble doesn't handle
178 // the operation. It's equivalent to having an IEEE number with consecutive
179 // 106 bits of mantissa and 11 bits of exponent.
180 //
181 // It's not equivalent to IBM double-double. For example, a legit IBM
182 // double-double, 1 + epsilon:
183 //
184 // 1 + epsilon = 1 + (1 >> 1076)
185 //
186 // is not representable by a consecutive 106 bits of mantissa.
187 //
188 // Currently, these semantics are used in the following way:
189 //
190 // semPPCDoubleDouble -> (IEEEdouble, IEEEdouble) ->
191 // (64-bit APInt, 64-bit APInt) -> (128-bit APInt) ->
192 // semPPCDoubleDoubleLegacy -> IEEE operations
193 //
194 // We use bitcastToAPInt() to get the bit representation (in APInt) of the
195 // underlying IEEEdouble, then use the APInt constructor to construct the
196 // legacy IEEE float.
197 //
198 // TODO: Implement all operations in semPPCDoubleDouble, and delete these
199 // semantics.
201 // 8-bit floating point number following IEEE-754 conventions with bit
202 // layout S1E5M2 as described in https://arxiv.org/abs/2209.05433.
204 // 8-bit floating point number mostly following IEEE-754 conventions
205 // and bit layout S1E5M2 described in https://arxiv.org/abs/2206.02915,
206 // with expanded range and with no infinity or signed zero.
207 // NaN is represented as negative zero. (FN -> Finite, UZ -> unsigned zero).
208 // This format's exponent bias is 16, instead of the 15 (2 ** (5 - 1) - 1)
209 // that IEEE precedent would imply.
211 // 8-bit floating point number following IEEE-754 conventions with bit
212 // layout S1E4M3.
214 // 8-bit floating point number mostly following IEEE-754 conventions with
215 // bit layout S1E4M3 as described in https://arxiv.org/abs/2209.05433.
216 // Unlike IEEE-754 types, there are no infinity values, and NaN is
217 // represented with the exponent and mantissa bits set to all 1s.
219 // 8-bit floating point number mostly following IEEE-754 conventions
220 // and bit layout S1E4M3 described in https://arxiv.org/abs/2206.02915,
221 // with expanded range and with no infinity or signed zero.
222 // NaN is represented as negative zero. (FN -> Finite, UZ -> unsigned zero).
223 // This format's exponent bias is 8, instead of the 7 (2 ** (4 - 1) - 1)
224 // that IEEE precedent would imply.
226 // 8-bit floating point number mostly following IEEE-754 conventions
227 // and bit layout S1E4M3 with expanded range and with no infinity or signed
228 // zero.
229 // NaN is represented as negative zero. (FN -> Finite, UZ -> unsigned zero).
230 // This format's exponent bias is 11, instead of the 7 (2 ** (4 - 1) - 1)
231 // that IEEE precedent would imply.
233 // 8-bit floating point number following IEEE-754 conventions with bit
234 // layout S1E3M4.
236 // Floating point number that occupies 32 bits or less of storage, providing
237 // improved range compared to half (16-bit) formats, at (potentially)
238 // greater throughput than single precision (32-bit) formats.
240 // 8-bit floating point number with (all the) 8 bits for the exponent
241 // like in FP32. There are no zeroes, no infinities, and no denormal values.
242 // This format has unsigned representation only. (U -> Unsigned only).
243 // NaN is represented with all bits set to 1. Bias is 127.
244 // This format represents the scale data type in the MX specification from:
245 // https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf
247 // 6-bit floating point number with bit layout S1E3M2. Unlike IEEE-754
248 // types, there are no infinity or NaN values. The format is detailed in
249 // https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf
251 // 6-bit floating point number with bit layout S1E2M3. Unlike IEEE-754
252 // types, there are no infinity or NaN values. The format is detailed in
253 // https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf
255 // 4-bit floating point number with bit layout S1E2M1. Unlike IEEE-754
256 // types, there are no infinity or NaN values. The format is detailed in
257 // https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf
259 // TODO: Documentation is missing.
262 };
263
266
267private:
268 LLVM_ABI static const fltSemantics semIEEEhalf;
269 LLVM_ABI static const fltSemantics semBFloat;
270 LLVM_ABI static const fltSemantics semIEEEsingle;
271 LLVM_ABI static const fltSemantics semIEEEdouble;
272 LLVM_ABI static const fltSemantics semIEEEquad;
273 LLVM_ABI static const fltSemantics semFloat8E5M2;
274 LLVM_ABI static const fltSemantics semFloat8E5M2FNUZ;
275 LLVM_ABI static const fltSemantics semFloat8E4M3;
276 LLVM_ABI static const fltSemantics semFloat8E4M3FN;
277 LLVM_ABI static const fltSemantics semFloat8E4M3FNUZ;
278 LLVM_ABI static const fltSemantics semFloat8E4M3B11FNUZ;
279 LLVM_ABI static const fltSemantics semFloat8E3M4;
280 LLVM_ABI static const fltSemantics semFloatTF32;
281 LLVM_ABI static const fltSemantics semFloat8E8M0FNU;
282 LLVM_ABI static const fltSemantics semFloat6E3M2FN;
283 LLVM_ABI static const fltSemantics semFloat6E2M3FN;
284 LLVM_ABI static const fltSemantics semFloat4E2M1FN;
285 LLVM_ABI static const fltSemantics semX87DoubleExtended;
286 LLVM_ABI static const fltSemantics semBogus;
287 LLVM_ABI static const fltSemantics semPPCDoubleDouble;
288 LLVM_ABI static const fltSemantics semPPCDoubleDoubleLegacy;
289
290 friend class detail::IEEEFloat;
292 friend class APFloat;
293
294public:
295 static const fltSemantics &IEEEhalf() { return semIEEEhalf; }
296 static const fltSemantics &BFloat() { return semBFloat; }
297 static const fltSemantics &IEEEsingle() { return semIEEEsingle; }
298 static const fltSemantics &IEEEdouble() { return semIEEEdouble; }
299 static const fltSemantics &IEEEquad() { return semIEEEquad; }
300 static const fltSemantics &PPCDoubleDouble() { return semPPCDoubleDouble; }
302 return semPPCDoubleDoubleLegacy;
303 }
304 static const fltSemantics &Float8E5M2() { return semFloat8E5M2; }
305 static const fltSemantics &Float8E5M2FNUZ() { return semFloat8E5M2FNUZ; }
306 static const fltSemantics &Float8E4M3() { return semFloat8E4M3; }
307 static const fltSemantics &Float8E4M3FN() { return semFloat8E4M3FN; }
308 static const fltSemantics &Float8E4M3FNUZ() { return semFloat8E4M3FNUZ; }
310 return semFloat8E4M3B11FNUZ;
311 }
312 static const fltSemantics &Float8E3M4() { return semFloat8E3M4; }
313 static const fltSemantics &FloatTF32() { return semFloatTF32; }
314 static const fltSemantics &Float8E8M0FNU() { return semFloat8E8M0FNU; }
315 static const fltSemantics &Float6E3M2FN() { return semFloat6E3M2FN; }
316 static const fltSemantics &Float6E2M3FN() { return semFloat6E2M3FN; }
317 static const fltSemantics &Float4E2M1FN() { return semFloat4E2M1FN; }
319 return semX87DoubleExtended;
320 }
321
322 /// A Pseudo fltsemantic used to construct APFloats that cannot conflict with
323 /// anything real.
324 static const fltSemantics &Bogus() { return semBogus; }
325
326 // Returns true if any number described by this semantics can be precisely
327 // represented by the specified semantics. Does not take into account
328 // the value of fltNonfiniteBehavior, hasZero, hasSignedRepr.
329 LLVM_ABI static bool isRepresentableBy(const fltSemantics &A,
330 const fltSemantics &B);
331
332 /// @}
333
334 /// IEEE-754R 5.11: Floating Point Comparison Relations.
341
342 /// IEEE-754R 4.3: Rounding-direction attributes.
344
352
353 /// IEEE-754R 7: Default exception handling.
354 ///
355 /// opUnderflow or opOverflow are always returned or-ed with opInexact.
356 ///
357 /// APFloat models this behavior specified by IEEE-754:
358 /// "For operations producing results in floating-point format, the default
359 /// result of an operation that signals the invalid operation exception
360 /// shall be a quiet NaN."
361 enum opStatus {
362 opOK = 0x00,
368 };
369
370 /// Category of internally-represented number.
377
378 /// Convenience enum used to construct an uninitialized APFloat.
382
383 /// Enumeration of \c ilogb error results.
385 IEK_Zero = INT_MIN + 1,
386 IEK_NaN = INT_MIN,
387 IEK_Inf = INT_MAX
388 };
389
390 LLVM_ABI static unsigned int semanticsPrecision(const fltSemantics &);
393 LLVM_ABI static unsigned int semanticsSizeInBits(const fltSemantics &);
394 LLVM_ABI static unsigned int semanticsIntSizeInBits(const fltSemantics &,
395 bool);
396 LLVM_ABI static bool semanticsHasZero(const fltSemantics &);
397 LLVM_ABI static bool semanticsHasSignedRepr(const fltSemantics &);
398 LLVM_ABI static bool semanticsHasInf(const fltSemantics &);
399 LLVM_ABI static bool semanticsHasNaN(const fltSemantics &);
400 LLVM_ABI static bool isIEEELikeFP(const fltSemantics &);
401 LLVM_ABI static bool hasSignBitInMSB(const fltSemantics &);
402
403 // Returns true if any number described by \p Src can be precisely represented
404 // by a normal (not subnormal) value in \p Dst.
405 LLVM_ABI static bool isRepresentableAsNormalIn(const fltSemantics &Src,
406 const fltSemantics &Dst);
407
408 /// Returns the size of the floating point number (in bits) in the given
409 /// semantics.
410 LLVM_ABI static unsigned getSizeInBits(const fltSemantics &Sem);
411
412 /// Returns true if the given string is a valid arbitrary floating-point
413 /// format interpretation for llvm.convert.to.arbitrary.fp and
414 /// llvm.convert.from.arbitrary.fp intrinsics.
416
417 /// Returns the size in bits of a valid arbitrary floating-point format
418 /// string, or 0 if the string is not a valid format. Covers every format
419 /// accepted by isValidArbitraryFPFormat, not only those
420 /// getArbitraryFPSemantics can currently lower.
422
423 /// Returns the fltSemantics for a given arbitrary FP format string,
424 /// or nullptr if invalid.
426};
427
428namespace detail {
429
450static constexpr opStatus opOK = APFloatBase::opOK;
460
461class IEEEFloat final {
462public:
463 /// \name Constructors
464 /// @{
465
466 LLVM_ABI IEEEFloat(const fltSemantics &); // Default construct to +0.0
469 LLVM_ABI IEEEFloat(const fltSemantics &, const APInt &);
470 LLVM_ABI explicit IEEEFloat(double d);
471 LLVM_ABI explicit IEEEFloat(float f);
475
476 /// @}
477
478 /// Returns whether this instance allocated memory.
479 bool needsCleanup() const { return partCount() > 1; }
480
481 /// \name Convenience "constructors"
482 /// @{
483
484 /// @}
485
486 /// \name Arithmetic
487 /// @{
488
493 /// IEEE remainder.
495 /// C fmod, or llvm frem.
500 /// IEEE-754R 5.3.1: nextUp/nextDown.
501 LLVM_ABI opStatus next(bool nextDown);
502
503 /// @}
504
505 /// \name Sign operations.
506 /// @{
507
508 LLVM_ABI void changeSign();
509
510 /// @}
511
512 /// \name Conversions
513 /// @{
514
517 bool, roundingMode, bool *) const;
521 LLVM_ABI double convertToDouble() const;
522#ifdef HAS_IEE754_FLOAT128
523 LLVM_ABI float128 convertToQuad() const;
524#endif
525 LLVM_ABI float convertToFloat() const;
526
527 /// @}
528
529 /// The definition of equality is not straightforward for floating point, so
530 /// we won't use operator==. Use one of the following, or write whatever it
531 /// is you really mean.
532 bool operator==(const IEEEFloat &) const = delete;
533
534 /// IEEE comparison with another floating point number (NaNs compare
535 /// unordered, 0==-0).
536 LLVM_ABI cmpResult compare(const IEEEFloat &) const;
537
538 /// Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
539 LLVM_ABI bool bitwiseIsEqual(const IEEEFloat &) const;
540
541 /// Write out a hexadecimal representation of the floating point value to DST,
542 /// which must be of sufficient size, in the C99 form [-]0xh.hhhhp[+-]d.
543 /// Return the number of characters written, excluding the terminating NUL.
544 LLVM_ABI unsigned int convertToHexString(char *dst, unsigned int hexDigits,
545 bool upperCase, roundingMode) const;
546
547 /// \name IEEE-754R 5.7.2 General operations.
548 /// @{
549
550 /// IEEE-754R isSignMinus: Returns true if and only if the current value is
551 /// negative.
552 ///
553 /// This applies to zeros and NaNs as well.
554 bool isNegative() const { return sign; }
555
556 /// IEEE-754R isNormal: Returns true if and only if the current value is normal.
557 ///
558 /// This implies that the current value of the float is not zero, subnormal,
559 /// infinite, or NaN following the definition of normality from IEEE-754R.
560 bool isNormal() const { return !isDenormal() && isFiniteNonZero(); }
561
562 /// Returns true if and only if the current value is zero, subnormal, or
563 /// normal.
564 ///
565 /// This means that the value is not infinite or NaN.
566 bool isFinite() const { return !isNaN() && !isInfinity(); }
567
568 /// Returns true if and only if the float is plus or minus zero.
569 bool isZero() const { return category == fltCategory::fcZero; }
570
571 /// IEEE-754R isSubnormal(): Returns true if and only if the float is a
572 /// denormal.
573 LLVM_ABI bool isDenormal() const;
574
575 /// IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
576 bool isInfinity() const { return category == fcInfinity; }
577
578 /// Returns true if and only if the float is a quiet or signaling NaN.
579 bool isNaN() const { return category == fcNaN; }
580
581 /// Returns true if and only if the float is a signaling NaN.
582 LLVM_ABI bool isSignaling() const;
583
584 /// @}
585
586 /// \name Simple Queries
587 /// @{
588
589 fltCategory getCategory() const { return category; }
590 const fltSemantics &getSemantics() const { return *semantics; }
591 bool isNonZero() const { return category != fltCategory::fcZero; }
592 bool isFiniteNonZero() const { return isFinite() && !isZero(); }
593 bool isPosZero() const { return isZero() && !isNegative(); }
594 bool isNegZero() const { return isZero() && isNegative(); }
595
596 /// Returns true if and only if the number has the smallest possible non-zero
597 /// magnitude in the current semantics.
598 LLVM_ABI bool isSmallest() const;
599
600 /// Returns true if this is the smallest (by magnitude) normalized finite
601 /// number in the given semantics.
602 LLVM_ABI bool isSmallestNormalized() const;
603
604 /// Returns true if and only if the number has the largest possible finite
605 /// magnitude in the current semantics.
606 LLVM_ABI bool isLargest() const;
607
608 /// Returns true if and only if the number is an exact integer.
609 LLVM_ABI bool isInteger() const;
610
611 /// @}
612
615
616 /// Overload to compute a hash code for an APFloat value.
617 ///
618 /// Note that the use of hash codes for floating point values is in general
619 /// frought with peril. Equality is hard to define for these values. For
620 /// example, should negative and positive zero hash to different codes? Are
621 /// they equal or not? This hash value implementation specifically
622 /// emphasizes producing different codes for different inputs in order to
623 /// be used in canonicalization and memoization. As such, equality is
624 /// bitwiseIsEqual, and 0 != -0.
625 LLVM_ABI friend hash_code hash_value(const IEEEFloat &Arg);
626
627 /// Converts this value into a decimal string.
628 ///
629 /// \param FormatPrecision The maximum number of digits of
630 /// precision to output. If there are fewer digits available,
631 /// zero padding will not be used unless the value is
632 /// integral and small enough to be expressed in
633 /// FormatPrecision digits. 0 means to use the natural
634 /// precision of the number.
635 /// \param FormatMaxPadding The maximum number of zeros to
636 /// consider inserting before falling back to scientific
637 /// notation. 0 means to always use scientific notation.
638 ///
639 /// \param TruncateZero Indicate whether to remove the trailing zero in
640 /// fraction part or not. Also setting this parameter to false forcing
641 /// producing of output more similar to default printf behavior.
642 /// Specifically the lower e is used as exponent delimiter and exponent
643 /// always contains no less than two digits.
644 ///
645 /// Number Precision MaxPadding Result
646 /// ------ --------- ---------- ------
647 /// 1.01E+4 5 2 10100
648 /// 1.01E+4 4 2 1.01E+4
649 /// 1.01E+4 5 1 1.01E+4
650 /// 1.01E-2 5 2 0.0101
651 /// 1.01E-2 4 2 0.0101
652 /// 1.01E-2 4 1 1.01E-2
654 unsigned FormatPrecision = 0,
655 unsigned FormatMaxPadding = 3,
656 bool TruncateZero = true) const;
657
659
660 LLVM_ABI friend int ilogb(const IEEEFloat &Arg);
661
663
664 LLVM_ABI friend IEEEFloat frexp(const IEEEFloat &X, int &Exp, roundingMode);
665
666 /// \name Special value setters.
667 /// @{
668
669 LLVM_ABI void makeLargest(bool Neg = false);
670 LLVM_ABI void makeSmallest(bool Neg = false);
671 LLVM_ABI void makeNaN(bool SNaN = false, bool Neg = false,
672 const APInt *fill = nullptr);
673 LLVM_ABI void makeInf(bool Neg = false);
674 LLVM_ABI void makeZero(bool Neg = false);
675 LLVM_ABI void makeQuiet();
676
677 /// Returns the smallest (by magnitude) normalized finite number in the given
678 /// semantics.
679 ///
680 /// \param Negative - True iff the number should be negative
681 LLVM_ABI void makeSmallestNormalized(bool Negative = false);
682
683 /// @}
684
686
688
689private:
690 /// \name Simple Queries
691 /// @{
692
693 integerPart *significandParts();
694 const integerPart *significandParts() const;
695 LLVM_ABI unsigned int partCount() const;
696
697 /// @}
698
699 /// \name Significand operations.
700 /// @{
701
702 integerPart addSignificand(const IEEEFloat &);
703 integerPart subtractSignificand(const IEEEFloat &, integerPart);
704 // Exported for IEEEFloatUnitTestHelper.
705 LLVM_ABI lostFraction addOrSubtractSignificand(const IEEEFloat &,
706 bool subtract);
707 lostFraction multiplySignificand(const IEEEFloat &, IEEEFloat,
708 bool ignoreAddend = false);
709 lostFraction multiplySignificand(const IEEEFloat&);
710 lostFraction divideSignificand(const IEEEFloat &);
711 void incrementSignificand();
712 void initialize(const fltSemantics *);
713 void shiftSignificandLeft(unsigned int);
714 lostFraction shiftSignificandRight(unsigned int);
715 unsigned int significandLSB() const;
716 unsigned int significandMSB() const;
717 void zeroSignificand();
718 unsigned int getNumHighBits() const;
719 /// Return true if the significand excluding the integral bit is all ones.
720 bool isSignificandAllOnes() const;
721 bool isSignificandAllOnesExceptLSB() const;
722 /// Return true if the significand excluding the integral bit is all zeros.
723 bool isSignificandAllZeros() const;
724 bool isSignificandAllZerosExceptMSB() const;
725
726 /// @}
727
728 /// \name Arithmetic on special values.
729 /// @{
730
731 opStatus addOrSubtractSpecials(const IEEEFloat &, bool subtract);
732 opStatus divideSpecials(const IEEEFloat &);
733 opStatus multiplySpecials(const IEEEFloat &);
734 opStatus modSpecials(const IEEEFloat &);
735 opStatus remainderSpecials(const IEEEFloat&);
736
737 /// @}
738
739 /// \name Miscellany
740 /// @{
741
742 bool convertFromStringSpecials(StringRef str);
744 opStatus addOrSubtract(const IEEEFloat &, roundingMode, bool subtract);
745 opStatus handleOverflow(roundingMode);
746 bool roundAwayFromZero(roundingMode, lostFraction, unsigned int) const;
747 opStatus convertToSignExtendedInteger(MutableArrayRef<integerPart>,
748 unsigned int, bool, roundingMode,
749 bool *) const;
750 opStatus convertFromUnsignedParts(const integerPart *, unsigned int,
752 Expected<opStatus> convertFromHexadecimalString(StringRef, roundingMode);
753 Expected<opStatus> convertFromDecimalString(StringRef, roundingMode);
754 char *convertNormalToHexString(char *, unsigned int, bool,
755 roundingMode) const;
756 opStatus roundSignificandWithExponent(const integerPart *, unsigned int, int,
761
762 /// @}
763
764 template <const fltSemantics &S> APInt convertIEEEFloatToAPInt() const;
765 APInt convertHalfAPFloatToAPInt() const;
766 APInt convertBFloatAPFloatToAPInt() const;
767 APInt convertFloatAPFloatToAPInt() const;
768 APInt convertDoubleAPFloatToAPInt() const;
769 APInt convertQuadrupleAPFloatToAPInt() const;
770 APInt convertF80LongDoubleAPFloatToAPInt() const;
771 APInt convertPPCDoubleDoubleLegacyAPFloatToAPInt() const;
772 APInt convertFloat8E5M2APFloatToAPInt() const;
773 APInt convertFloat8E5M2FNUZAPFloatToAPInt() const;
774 APInt convertFloat8E4M3APFloatToAPInt() const;
775 APInt convertFloat8E4M3FNAPFloatToAPInt() const;
776 APInt convertFloat8E4M3FNUZAPFloatToAPInt() const;
777 APInt convertFloat8E4M3B11FNUZAPFloatToAPInt() const;
778 APInt convertFloat8E3M4APFloatToAPInt() const;
779 APInt convertFloatTF32APFloatToAPInt() const;
780 APInt convertFloat8E8M0FNUAPFloatToAPInt() const;
781 APInt convertFloat6E3M2FNAPFloatToAPInt() const;
782 APInt convertFloat6E2M3FNAPFloatToAPInt() const;
783 APInt convertFloat4E2M1FNAPFloatToAPInt() const;
784 void initFromAPInt(const fltSemantics *Sem, const APInt &api);
785 template <const fltSemantics &S> void initFromIEEEAPInt(const APInt &api);
786 void initFromHalfAPInt(const APInt &api);
787 void initFromBFloatAPInt(const APInt &api);
788 void initFromFloatAPInt(const APInt &api);
789 void initFromDoubleAPInt(const APInt &api);
790 void initFromQuadrupleAPInt(const APInt &api);
791 void initFromF80LongDoubleAPInt(const APInt &api);
792 void initFromPPCDoubleDoubleLegacyAPInt(const APInt &api);
793 void initFromFloat8E5M2APInt(const APInt &api);
794 void initFromFloat8E5M2FNUZAPInt(const APInt &api);
795 void initFromFloat8E4M3APInt(const APInt &api);
796 void initFromFloat8E4M3FNAPInt(const APInt &api);
797 void initFromFloat8E4M3FNUZAPInt(const APInt &api);
798 void initFromFloat8E4M3B11FNUZAPInt(const APInt &api);
799 void initFromFloat8E3M4APInt(const APInt &api);
800 void initFromFloatTF32APInt(const APInt &api);
801 void initFromFloat8E8M0FNUAPInt(const APInt &api);
802 void initFromFloat6E3M2FNAPInt(const APInt &api);
803 void initFromFloat6E2M3FNAPInt(const APInt &api);
804 void initFromFloat4E2M1FNAPInt(const APInt &api);
805
806 void assign(const IEEEFloat &);
807 void copySignificand(const IEEEFloat &);
808 void freeSignificand();
809
810 /// Note: this must be the first data member.
811 /// The semantics that this value obeys.
812 const fltSemantics *semantics;
813
814 /// A binary fraction with an explicit integer bit.
815 ///
816 /// The significand must be at least one bit wider than the target precision.
817 union Significand {
818 integerPart part;
819 integerPart *parts;
820 } significand;
821
822 /// The signed unbiased exponent of the value.
823 ExponentType exponent;
824
825 /// What kind of floating point number this is.
826 ///
827 /// Only 2 bits are required, but VisualStudio incorrectly sign extends it.
828 /// Using the extra bit keeps it from failing under VisualStudio.
829 fltCategory category : 3;
830
831 /// Sign bit of the number.
832 unsigned int sign : 1;
833
835};
836
838LLVM_ABI int ilogb(const IEEEFloat &Arg);
840LLVM_ABI IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM);
841
842// This mode implements more precise float in terms of two APFloats.
843// The interface and layout is designed for arbitrary underlying semantics,
844// though currently only PPCDoubleDouble semantics are supported, whose
845// corresponding underlying semantics are IEEEdouble.
846class DoubleAPFloat final {
847 // Note: this must be the first data member.
848 const fltSemantics *Semantics;
849 APFloat *Floats;
850
851 opStatus addImpl(const APFloat &a, const APFloat &aa, const APFloat &c,
852 const APFloat &cc, roundingMode RM);
853
854 opStatus addWithSpecial(const DoubleAPFloat &LHS, const DoubleAPFloat &RHS,
855 DoubleAPFloat &Out, roundingMode RM);
856 opStatus convertToSignExtendedInteger(MutableArrayRef<integerPart> Input,
857 unsigned int Width, bool IsSigned,
858 roundingMode RM, bool *IsExact) const;
859
860 // Convert an unsigned integer Src to a floating point number,
861 // rounding according to RM. The sign of the floating point number is not
862 // modified.
863 opStatus convertFromUnsignedParts(const integerPart *Src,
864 unsigned int SrcCount, roundingMode RM);
865
866 // Handle overflow. Sign is preserved. We either become infinity or
867 // the largest finite number.
868 opStatus handleOverflow(roundingMode RM);
869
870public:
874 LLVM_ABI DoubleAPFloat(const fltSemantics &S, const APInt &I);
876 APFloat &&Second);
880
883
884 bool needsCleanup() const { return Floats != nullptr; }
885
886 inline APFloat &getFirst();
887 inline const APFloat &getFirst() const;
888 inline APFloat &getSecond();
889 inline const APFloat &getSecond() const;
890
898 const DoubleAPFloat &Addend,
899 roundingMode RM);
901 LLVM_ABI void changeSign();
903
905 LLVM_ABI bool isNegative() const;
906
907 LLVM_ABI void makeInf(bool Neg);
908 LLVM_ABI void makeZero(bool Neg);
909 LLVM_ABI void makeLargest(bool Neg);
910 LLVM_ABI void makeSmallest(bool Neg);
911 LLVM_ABI void makeSmallestNormalized(bool Neg);
912 LLVM_ABI void makeNaN(bool SNaN, bool Neg, const APInt *fill);
913
915 LLVM_ABI bool bitwiseIsEqual(const DoubleAPFloat &RHS) const;
918 LLVM_ABI opStatus next(bool nextDown);
919
921 unsigned int Width, bool IsSigned,
922 roundingMode RM, bool *IsExact) const;
923 LLVM_ABI opStatus convertFromAPInt(const APInt &Input, bool IsSigned,
924 roundingMode RM);
925 LLVM_ABI unsigned int convertToHexString(char *DST, unsigned int HexDigits,
926 bool UpperCase,
927 roundingMode RM) const;
928
929 LLVM_ABI bool isDenormal() const;
930 LLVM_ABI bool isSmallest() const;
931 LLVM_ABI bool isSmallestNormalized() const;
932 LLVM_ABI bool isLargest() const;
933 LLVM_ABI bool isInteger() const;
934
936
937 LLVM_ABI void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision,
938 unsigned FormatMaxPadding,
939 bool TruncateZero = true) const;
940
942
943 LLVM_ABI friend int ilogb(const DoubleAPFloat &X);
946 LLVM_ABI friend DoubleAPFloat frexp(const DoubleAPFloat &X, int &Exp,
948 LLVM_ABI friend hash_code hash_value(const DoubleAPFloat &Arg);
949};
950
952LLVM_ABI DoubleAPFloat scalbn(const DoubleAPFloat &Arg, int Exp,
953 roundingMode RM);
955
956} // End detail namespace
957
958// How the nonfinite values Inf and NaN are represented.
960 // Represents standard IEEE 754 behavior. A value is nonfinite if the
961 // exponent field is all 1s. In such cases, a value is Inf if the
962 // significand bits are all zero, and NaN otherwise
964
965 // This behavior is present in the Float8ExMyFN* types (Float8E4M3FN,
966 // Float8E5M2FNUZ, Float8E4M3FNUZ, and Float8E4M3B11FNUZ). There is no
967 // representation for Inf, and operations that would ordinarily produce Inf
968 // produce NaN instead.
969 // The details of the NaN representation(s) in this form are determined by the
970 // `fltNanEncoding` enum. We treat all NaNs as quiet, as the available
971 // encodings do not distinguish between signalling and quiet NaN.
973
974 // This behavior is present in Float6E3M2FN, Float6E2M3FN, and
975 // Float4E2M1FN types, which do not support Inf or NaN values.
977};
978
979// How NaN values are represented. This is curently only used in combination
980// with fltNonfiniteBehavior::NanOnly, and using a variant other than IEEE
981// while having IEEE non-finite behavior is liable to lead to unexpected
982// results.
983enum class fltNanEncoding {
984 // Represents the standard IEEE behavior where a value is NaN if its
985 // exponent is all 1s and the significand is non-zero.
987
988 // Represents the behavior in the Float8E4M3FN floating point type where NaN
989 // is represented by having the exponent and mantissa set to all 1s.
990 // This behavior matches the FP8 E4M3 type described in
991 // https://arxiv.org/abs/2209.05433. We treat both signed and unsigned NaNs
992 // as non-signalling, although the paper does not state whether the NaN
993 // values are signalling or not.
995
996 // Represents the behavior in Float8E{5,4}E{2,3}FNUZ floating point types
997 // where NaN is represented by a sign bit of 1 and all 0s in the exponent
998 // and mantissa (i.e. the negative zero encoding in a IEEE float). Since
999 // there is only one NaN value, it is treated as quiet NaN. This matches the
1000 // behavior described in https://arxiv.org/abs/2206.02915 .
1002};
1003
1004/* Represents floating point arithmetic semantics. */
1006 /* The largest E such that 2^E is representable; this matches the
1007 definition of IEEE 754. */
1009
1010 /* The smallest E such that 2^E is a normalized number; this
1011 matches the definition of IEEE 754. */
1013
1014 /* Number of bits in the significand. This includes the integer
1015 bit. */
1016 unsigned int precision;
1017
1018 /* Number of bits actually used in the semantics. */
1019 unsigned int sizeInBits;
1020
1022
1024
1025 /* Whether this semantics has an encoding for Zero */
1026 bool hasZero = true;
1027
1028 /* Whether this semantics can represent signed values */
1029 bool hasSignedRepr = true;
1030
1031 /* Whether the sign bit of this semantics is the most significant bit */
1032 bool hasSignBitInMSB = true;
1033
1034 /* Whether the format supports IEEE754 denormal representation.
1035 If both hasDenormals and hasZero are false exponent 0 is assumed to be a
1036 regular exponent instead of being reserved. This changes the bias by +1. */
1037 bool hasDenormals = true;
1038
1039 /* Whether the integer bit is explicitly represented between significant and
1040 exponent, for example as specified by the x86 double extended precision
1041 format.
1042
1043 For bit patterns designated as undefined under the standard the following
1044 conversions will happen when converting from bits. These follow x87
1045 behaviour:
1046 - exponent = all 1's, integer bit 0, significand 0 ("pseudoinfinity")
1047 - exponent = all 1's, integer bit 0, significand nonzero ("pseudoNaN")
1048 - exponent!=0 nor all 1's, integer bit 0 ("unnormal")
1049 - exponent = 0, integer bit 1 ("pseudodenormal")
1050 The first three are treated as NaNs, the last one as Normal */
1052};
1053
1054// This is a interface class that is currently forwarding functionalities from
1055// detail::IEEEFloat.
1056class APFloat : public APFloatBase {
1057 using IEEEFloat = detail::IEEEFloat;
1058 using DoubleAPFloat = detail::DoubleAPFloat;
1059
1060 static_assert(std::is_standard_layout<IEEEFloat>::value);
1061
1062 union Storage {
1063 const fltSemantics *semantics;
1064 IEEEFloat IEEE;
1065 DoubleAPFloat Double;
1066
1067 LLVM_ABI explicit Storage(IEEEFloat F, const fltSemantics &S);
1068 explicit Storage(DoubleAPFloat F, const fltSemantics &S)
1069 : Double(std::move(F)) {
1070 assert(&S == &PPCDoubleDouble());
1071 }
1072
1073 template <typename... ArgTypes>
1074 Storage(const fltSemantics &Semantics, ArgTypes &&... Args) {
1075 if (usesLayout<IEEEFloat>(Semantics)) {
1076 new (&IEEE) IEEEFloat(Semantics, std::forward<ArgTypes>(Args)...);
1077 return;
1078 }
1079 if (usesLayout<DoubleAPFloat>(Semantics)) {
1080 new (&Double) DoubleAPFloat(Semantics, std::forward<ArgTypes>(Args)...);
1081 return;
1082 }
1083 llvm_unreachable("Unexpected semantics");
1084 }
1085
1086 LLVM_ABI ~Storage();
1087 LLVM_ABI Storage(const Storage &RHS);
1088 LLVM_ABI Storage(Storage &&RHS);
1089 LLVM_ABI Storage &operator=(const Storage &RHS);
1090 LLVM_ABI Storage &operator=(Storage &&RHS);
1091 } U;
1092
1093 template <typename T> static bool usesLayout(const fltSemantics &Semantics) {
1094 static_assert(std::is_same<T, IEEEFloat>::value ||
1095 std::is_same<T, DoubleAPFloat>::value);
1096 if (std::is_same<T, DoubleAPFloat>::value) {
1097 return &Semantics == &PPCDoubleDouble();
1098 }
1099 return &Semantics != &PPCDoubleDouble();
1100 }
1101
1102 IEEEFloat &getIEEE() {
1103 if (usesLayout<IEEEFloat>(*U.semantics))
1104 return U.IEEE;
1105 if (usesLayout<DoubleAPFloat>(*U.semantics))
1106 return U.Double.getFirst().U.IEEE;
1107 llvm_unreachable("Unexpected semantics");
1108 }
1109
1110 const IEEEFloat &getIEEE() const {
1111 if (usesLayout<IEEEFloat>(*U.semantics))
1112 return U.IEEE;
1113 if (usesLayout<DoubleAPFloat>(*U.semantics))
1114 return U.Double.getFirst().U.IEEE;
1115 llvm_unreachable("Unexpected semantics");
1116 }
1117
1118 void makeZero(bool Neg) { APFLOAT_DISPATCH_ON_SEMANTICS(makeZero(Neg)); }
1119
1120 void makeInf(bool Neg) { APFLOAT_DISPATCH_ON_SEMANTICS(makeInf(Neg)); }
1121
1122 void makeNaN(bool SNaN, bool Neg, const APInt *fill) {
1123 APFLOAT_DISPATCH_ON_SEMANTICS(makeNaN(SNaN, Neg, fill));
1124 }
1125
1126 void makeLargest(bool Neg) {
1127 APFLOAT_DISPATCH_ON_SEMANTICS(makeLargest(Neg));
1128 }
1129
1130 void makeSmallest(bool Neg) {
1131 APFLOAT_DISPATCH_ON_SEMANTICS(makeSmallest(Neg));
1132 }
1133
1134 void makeSmallestNormalized(bool Neg) {
1135 APFLOAT_DISPATCH_ON_SEMANTICS(makeSmallestNormalized(Neg));
1136 }
1137
1138 explicit APFloat(IEEEFloat F, const fltSemantics &S) : U(std::move(F), S) {}
1139 explicit APFloat(DoubleAPFloat F, const fltSemantics &S)
1140 : U(std::move(F), S) {}
1141
1142public:
1146 template <typename T,
1147 typename = std::enable_if_t<std::is_floating_point<T>::value>>
1148 APFloat(const fltSemantics &Semantics, T V) = delete;
1149 // TODO: Remove this constructor. This isn't faster than the first one.
1153 explicit APFloat(double d) : U(IEEEFloat(d), IEEEdouble()) {}
1154 explicit APFloat(float f) : U(IEEEFloat(f), IEEEsingle()) {}
1155 APFloat(const APFloat &RHS) = default;
1156 APFloat(APFloat &&RHS) = default;
1157
1158 ~APFloat() = default;
1159
1161
1162 /// Factory for Positive and Negative Zero.
1163 ///
1164 /// \param Negative True iff the number should be negative.
1165 static APFloat getZero(const fltSemantics &Sem, bool Negative = false) {
1166 APFloat Val(Sem, uninitialized);
1167 Val.makeZero(Negative);
1168 return Val;
1169 }
1170
1171 /// Factory for Positive and Negative One.
1172 ///
1173 /// \param Negative True iff the number should be negative.
1174 static APFloat getOne(const fltSemantics &Sem, bool Negative = false) {
1175 APFloat Val(Sem, 1U);
1176 if (Negative)
1177 Val.changeSign();
1178 return Val;
1179 }
1180
1181 /// Factory for Positive and Negative Infinity.
1182 ///
1183 /// \param Negative True iff the number should be negative.
1184 static APFloat getInf(const fltSemantics &Sem, bool Negative = false) {
1185 APFloat Val(Sem, uninitialized);
1186 Val.makeInf(Negative);
1187 return Val;
1188 }
1189
1190 /// Factory for NaN values.
1191 ///
1192 /// \param Negative - True iff the NaN generated should be negative.
1193 /// \param payload - The unspecified fill bits for creating the NaN, 0 by
1194 /// default. The value is truncated as necessary.
1195 static APFloat getNaN(const fltSemantics &Sem, bool Negative = false,
1196 uint64_t payload = 0) {
1197 if (payload) {
1198 APInt intPayload(64, payload);
1199 return getQNaN(Sem, Negative, &intPayload);
1200 } else {
1201 return getQNaN(Sem, Negative, nullptr);
1202 }
1203 }
1204
1205 /// Factory for QNaN values.
1206 static APFloat getQNaN(const fltSemantics &Sem, bool Negative = false,
1207 const APInt *payload = nullptr) {
1208 APFloat Val(Sem, uninitialized);
1209 Val.makeNaN(false, Negative, payload);
1210 return Val;
1211 }
1212
1213 /// Factory for SNaN values.
1214 static APFloat getSNaN(const fltSemantics &Sem, bool Negative = false,
1215 const APInt *payload = nullptr) {
1216 APFloat Val(Sem, uninitialized);
1217 Val.makeNaN(true, Negative, payload);
1218 return Val;
1219 }
1220
1221 /// Returns the largest finite number in the given semantics.
1222 ///
1223 /// \param Negative - True iff the number should be negative
1224 static APFloat getLargest(const fltSemantics &Sem, bool Negative = false) {
1225 APFloat Val(Sem, uninitialized);
1226 Val.makeLargest(Negative);
1227 return Val;
1228 }
1229
1230 /// Returns the smallest (by magnitude) finite number in the given semantics.
1231 /// Might be denormalized, which implies a relative loss of precision.
1232 ///
1233 /// \param Negative - True iff the number should be negative
1234 static APFloat getSmallest(const fltSemantics &Sem, bool Negative = false) {
1235 APFloat Val(Sem, uninitialized);
1236 Val.makeSmallest(Negative);
1237 return Val;
1238 }
1239
1240 /// Returns the smallest (by magnitude) normalized finite number in the given
1241 /// semantics.
1242 ///
1243 /// \param Negative - True iff the number should be negative
1244 static APFloat getSmallestNormalized(const fltSemantics &Sem,
1245 bool Negative = false) {
1246 APFloat Val(Sem, uninitialized);
1247 Val.makeSmallestNormalized(Negative);
1248 return Val;
1249 }
1250
1251 /// Returns a float which is bitcasted from an all one value int.
1252 ///
1253 /// \param Semantics - type float semantics
1255
1256 /// Returns true if the given semantics has actual significand.
1257 ///
1258 /// \param Sem - type float semantics
1259 static bool hasSignificand(const fltSemantics &Sem) {
1260 return &Sem != &Float8E8M0FNU();
1261 }
1262
1263 /// Used to insert APFloat objects, or objects that contain APFloat objects,
1264 /// into FoldingSets.
1265 LLVM_ABI void Profile(FoldingSetNodeID &NID) const;
1266
1267 opStatus add(const APFloat &RHS, roundingMode RM) {
1268 assert(&getSemantics() == &RHS.getSemantics() &&
1269 "Should only call on two APFloats with the same semantics");
1270 if (usesLayout<IEEEFloat>(getSemantics()))
1271 return U.IEEE.add(RHS.U.IEEE, RM);
1272 if (usesLayout<DoubleAPFloat>(getSemantics()))
1273 return U.Double.add(RHS.U.Double, RM);
1274 llvm_unreachable("Unexpected semantics");
1275 }
1276 opStatus subtract(const APFloat &RHS, roundingMode RM) {
1277 assert(&getSemantics() == &RHS.getSemantics() &&
1278 "Should only call on two APFloats with the same semantics");
1279 if (usesLayout<IEEEFloat>(getSemantics()))
1280 return U.IEEE.subtract(RHS.U.IEEE, RM);
1281 if (usesLayout<DoubleAPFloat>(getSemantics()))
1282 return U.Double.subtract(RHS.U.Double, RM);
1283 llvm_unreachable("Unexpected semantics");
1284 }
1285 opStatus multiply(const APFloat &RHS, roundingMode RM) {
1286 assert(&getSemantics() == &RHS.getSemantics() &&
1287 "Should only call on two APFloats with the same semantics");
1288 if (usesLayout<IEEEFloat>(getSemantics()))
1289 return U.IEEE.multiply(RHS.U.IEEE, RM);
1290 if (usesLayout<DoubleAPFloat>(getSemantics()))
1291 return U.Double.multiply(RHS.U.Double, RM);
1292 llvm_unreachable("Unexpected semantics");
1293 }
1294 opStatus divide(const APFloat &RHS, roundingMode RM) {
1295 assert(&getSemantics() == &RHS.getSemantics() &&
1296 "Should only call on two APFloats with the same semantics");
1297 if (usesLayout<IEEEFloat>(getSemantics()))
1298 return U.IEEE.divide(RHS.U.IEEE, RM);
1299 if (usesLayout<DoubleAPFloat>(getSemantics()))
1300 return U.Double.divide(RHS.U.Double, RM);
1301 llvm_unreachable("Unexpected semantics");
1302 }
1303 opStatus remainder(const APFloat &RHS) {
1304 assert(&getSemantics() == &RHS.getSemantics() &&
1305 "Should only call on two APFloats with the same semantics");
1306 if (usesLayout<IEEEFloat>(getSemantics()))
1307 return U.IEEE.remainder(RHS.U.IEEE);
1308 if (usesLayout<DoubleAPFloat>(getSemantics()))
1309 return U.Double.remainder(RHS.U.Double);
1310 llvm_unreachable("Unexpected semantics");
1311 }
1312 opStatus mod(const APFloat &RHS) {
1313 assert(&getSemantics() == &RHS.getSemantics() &&
1314 "Should only call on two APFloats with the same semantics");
1315 if (usesLayout<IEEEFloat>(getSemantics()))
1316 return U.IEEE.mod(RHS.U.IEEE);
1317 if (usesLayout<DoubleAPFloat>(getSemantics()))
1318 return U.Double.mod(RHS.U.Double);
1319 llvm_unreachable("Unexpected semantics");
1320 }
1321 opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend,
1322 roundingMode RM) {
1323 assert(&getSemantics() == &Multiplicand.getSemantics() &&
1324 "Should only call on APFloats with the same semantics");
1325 assert(&getSemantics() == &Addend.getSemantics() &&
1326 "Should only call on APFloats with the same semantics");
1327 if (usesLayout<IEEEFloat>(getSemantics()))
1328 return U.IEEE.fusedMultiplyAdd(Multiplicand.U.IEEE, Addend.U.IEEE, RM);
1329 if (usesLayout<DoubleAPFloat>(getSemantics()))
1330 return U.Double.fusedMultiplyAdd(Multiplicand.U.Double, Addend.U.Double,
1331 RM);
1332 llvm_unreachable("Unexpected semantics");
1333 }
1337
1338 // TODO: bool parameters are not readable and a source of bugs.
1339 // Do something.
1340 opStatus next(bool nextDown) {
1342 }
1343
1344 /// Negate an APFloat.
1345 APFloat operator-() const {
1346 APFloat Result(*this);
1347 Result.changeSign();
1348 return Result;
1349 }
1350
1351 /// Add two APFloats, rounding ties to the nearest even.
1352 /// No error checking.
1353 APFloat operator+(const APFloat &RHS) const {
1354 APFloat Result(*this);
1355 (void)Result.add(RHS, rmNearestTiesToEven);
1356 return Result;
1357 }
1358
1359 /// Subtract two APFloats, rounding ties to the nearest even.
1360 /// No error checking.
1361 APFloat operator-(const APFloat &RHS) const {
1362 APFloat Result(*this);
1363 (void)Result.subtract(RHS, rmNearestTiesToEven);
1364 return Result;
1365 }
1366
1367 /// Multiply two APFloats, rounding ties to the nearest even.
1368 /// No error checking.
1369 APFloat operator*(const APFloat &RHS) const {
1370 APFloat Result(*this);
1371 (void)Result.multiply(RHS, rmNearestTiesToEven);
1372 return Result;
1373 }
1374
1375 /// Divide the first APFloat by the second, rounding ties to the nearest even.
1376 /// No error checking.
1377 APFloat operator/(const APFloat &RHS) const {
1378 APFloat Result(*this);
1379 (void)Result.divide(RHS, rmNearestTiesToEven);
1380 return Result;
1381 }
1382
1384 void clearSign() {
1385 if (isNegative())
1386 changeSign();
1387 }
1388 void copySign(const APFloat &RHS) {
1389 if (isNegative() != RHS.isNegative())
1390 changeSign();
1391 }
1392
1393 /// A static helper to produce a copy of an APFloat value with its sign
1394 /// copied from some other APFloat.
1395 static APFloat copySign(APFloat Value, const APFloat &Sign) {
1396 Value.copySign(Sign);
1397 return Value;
1398 }
1399
1400 /// Assuming this is an IEEE-754 NaN value, quiet its signaling bit.
1401 /// This preserves the sign and payload bits.
1402 [[nodiscard]] APFloat makeQuiet() const {
1403 APFloat Result(*this);
1404 Result.getIEEE().makeQuiet();
1405 return Result;
1406 }
1407
1408 LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM,
1409 bool *losesInfo);
1410 // Convert a floating point number to an integer according to the
1411 // rounding mode. We provide deterministic values in case of an invalid
1412 // operation exception, namely zero for NaNs and the minimal or maximal value
1413 // respectively for underflow or overflow.
1414 // The *IsExact output tells whether the result is exact, in the sense that
1415 // converting it back to the original floating point type produces the
1416 // original value. This is almost equivalent to result==opOK, except for
1417 // negative zeroes.
1419 unsigned int Width, bool IsSigned, roundingMode RM,
1420 bool *IsExact) const {
1422 convertToInteger(Input, Width, IsSigned, RM, IsExact));
1423 }
1424 // Same as convertToInteger(integerPart*, ...), except the result is returned
1425 // in an APSInt, whose initial bit-width and signed-ness are used to determine
1426 // the precision of the conversion.
1428 bool *IsExact) const;
1429
1430 // Convert a two's complement integer Input to a floating point number,
1431 // rounding according to RM. IsSigned is true if the integer is signed,
1432 // in which case it must be sign-extended.
1433 opStatus convertFromAPInt(const APInt &Input, bool IsSigned,
1434 roundingMode RM) {
1436 }
1437
1438 /// Fill this APFloat with the result of a string conversion.
1439 ///
1440 /// The following strings are accepted for conversion purposes:
1441 /// * Decimal floating-point literals (e.g., `0.1e-5`)
1442 /// * Hexadecimal floating-point literals (e.g., `0x1.0p-5`)
1443 /// * Positive infinity via "inf", "INFINITY", "Inf", "+Inf", or "+inf".
1444 /// * Negative infinity via "-inf", "-INFINITY", or "-Inf".
1445 /// * Quiet NaNs via "nan", "NaN", "nan(...)", or "NaN(...)", where the
1446 /// "..." is either a decimal or hexadecimal integer representing the
1447 /// payload. A negative sign may be optionally provided.
1448 /// * Signaling NaNs via "snan", "sNaN", "snan(...)", or "sNaN(...)", where
1449 /// the "..." is either a decimal or hexadecimal integer representing the
1450 /// payload. A negative sign may be optionally provided.
1451 ///
1452 /// If the input string is none of these forms, then an error is returned.
1453 ///
1454 /// If a floating-point exception occurs during conversion, then no error is
1455 /// returned, and the exception is indicated via opStatus.
1460
1461 /// Converts this APFloat to host double value.
1462 ///
1463 /// \pre The APFloat must be built using semantics, that can be represented by
1464 /// the host double type without loss of precision. It can be IEEEdouble and
1465 /// shorter semantics, like IEEEsingle and others.
1466 LLVM_ABI double convertToDouble() const;
1467
1468 /// Converts this APFloat to host float value.
1469 ///
1470 /// \pre The APFloat must be built using semantics, that can be represented by
1471 /// the host float type without loss of precision. It can be IEEEquad and
1472 /// shorter semantics, like IEEEdouble and others.
1473#ifdef HAS_IEE754_FLOAT128
1474 LLVM_ABI float128 convertToQuad() const;
1475#endif
1476
1477 /// Converts this APFloat to host float value.
1478 ///
1479 /// \pre The APFloat must be built using semantics, that can be represented by
1480 /// the host float type without loss of precision. It can be IEEEsingle and
1481 /// shorter semantics, like IEEEhalf.
1482 LLVM_ABI float convertToFloat() const;
1483
1484 bool operator==(const APFloat &RHS) const { return compare(RHS) == cmpEqual; }
1485
1486 bool operator!=(const APFloat &RHS) const { return compare(RHS) != cmpEqual; }
1487
1488 bool operator<(const APFloat &RHS) const {
1489 return compare(RHS) == cmpLessThan;
1490 }
1491
1492 bool operator>(const APFloat &RHS) const {
1493 return compare(RHS) == cmpGreaterThan;
1494 }
1495
1496 bool operator<=(const APFloat &RHS) const {
1497 cmpResult Res = compare(RHS);
1498 return Res == cmpLessThan || Res == cmpEqual;
1499 }
1500
1501 bool operator>=(const APFloat &RHS) const {
1502 cmpResult Res = compare(RHS);
1503 return Res == cmpGreaterThan || Res == cmpEqual;
1504 }
1505
1506 // IEEE comparison with another floating point number (NaNs compare unordered,
1507 // 0==-0).
1508 cmpResult compare(const APFloat &RHS) const {
1509 assert(&getSemantics() == &RHS.getSemantics() &&
1510 "Should only compare APFloats with the same semantics");
1511 if (usesLayout<IEEEFloat>(getSemantics()))
1512 return U.IEEE.compare(RHS.U.IEEE);
1513 if (usesLayout<DoubleAPFloat>(getSemantics()))
1514 return U.Double.compare(RHS.U.Double);
1515 llvm_unreachable("Unexpected semantics");
1516 }
1517
1518 // Compares the absolute value of this APFloat with another. Both operands
1519 // must be finite non-zero.
1520 cmpResult compareAbsoluteValue(const APFloat &RHS) const {
1521 assert(&getSemantics() == &RHS.getSemantics() &&
1522 "Should only compare APFloats with the same semantics");
1523 if (usesLayout<IEEEFloat>(getSemantics()))
1524 return U.IEEE.compareAbsoluteValue(RHS.U.IEEE);
1525 if (usesLayout<DoubleAPFloat>(getSemantics()))
1526 return U.Double.compareAbsoluteValue(RHS.U.Double);
1527 llvm_unreachable("Unexpected semantics");
1528 }
1529
1530 bool bitwiseIsEqual(const APFloat &RHS) const {
1531 if (&getSemantics() != &RHS.getSemantics())
1532 return false;
1533 if (usesLayout<IEEEFloat>(getSemantics()))
1534 return U.IEEE.bitwiseIsEqual(RHS.U.IEEE);
1535 if (usesLayout<DoubleAPFloat>(getSemantics()))
1536 return U.Double.bitwiseIsEqual(RHS.U.Double);
1537 llvm_unreachable("Unexpected semantics");
1538 }
1539
1540 /// We don't rely on operator== working on double values, as
1541 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1542 /// As such, this method can be used to do an exact bit-for-bit comparison of
1543 /// two floating point values.
1544 ///
1545 /// We leave the version with the double argument here because it's just so
1546 /// convenient to write "2.0" and the like. Without this function we'd
1547 /// have to duplicate its logic everywhere it's called.
1548 bool isExactlyValue(double V) const {
1549 bool ignored;
1550 APFloat Tmp(V);
1552 return bitwiseIsEqual(Tmp);
1553 }
1554
1555 unsigned int convertToHexString(char *DST, unsigned int HexDigits,
1556 bool UpperCase, roundingMode RM) const {
1558 convertToHexString(DST, HexDigits, UpperCase, RM));
1559 }
1560
1561 bool isZero() const { return getCategory() == fcZero; }
1562 bool isInfinity() const { return getCategory() == fcInfinity; }
1563 bool isNaN() const { return getCategory() == fcNaN; }
1564
1565 bool isNegative() const { return getIEEE().isNegative(); }
1567 bool isSignaling() const { return getIEEE().isSignaling(); }
1568
1569 bool isNormal() const { return !isDenormal() && isFiniteNonZero(); }
1570 bool isFinite() const { return !isNaN() && !isInfinity(); }
1571
1572 fltCategory getCategory() const { return getIEEE().getCategory(); }
1573 const fltSemantics &getSemantics() const { return *U.semantics; }
1574 bool isNonZero() const { return !isZero(); }
1575 bool isFiniteNonZero() const { return isFinite() && !isZero(); }
1576 bool isPosZero() const { return isZero() && !isNegative(); }
1577 bool isNegZero() const { return isZero() && isNegative(); }
1578 bool isPosInfinity() const { return isInfinity() && !isNegative(); }
1579 bool isNegInfinity() const { return isInfinity() && isNegative(); }
1583
1587
1588 /// If the value is a NaN value, return an integer containing the payload of
1589 /// this value. This payload will include the quiet bit as part of the
1590 /// returned integer.
1592 assert(isNaN() && "Can only call this on a NaN value");
1594 }
1595
1596 /// Return the FPClassTest which will return true for the value.
1598
1599 APFloat &operator=(const APFloat &RHS) = default;
1600 APFloat &operator=(APFloat &&RHS) = default;
1601
1602 void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision = 0,
1603 unsigned FormatMaxPadding = 3, bool TruncateZero = true) const {
1605 toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero));
1606 }
1607
1608 LLVM_ABI void print(raw_ostream &) const;
1609
1610#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1611 LLVM_DUMP_METHOD void dump() const;
1612#endif
1613
1614 /// If this value is normal and has an exact, normal, multiplicative inverse,
1615 /// store it in inv and return true.
1616 LLVM_ABI bool getExactInverse(APFloat *Inv) const;
1617
1618 // If this is an exact power of two, return the exponent while ignoring the
1619 // sign bit. If it's not an exact power of 2, return INT_MIN
1624
1625 // If this is an exact power of two, return the exponent. If it's not an exact
1626 // power of 2, return INT_MIN
1628 int getExactLog2() const {
1629 return isNegative() ? INT_MIN : getExactLog2Abs();
1630 }
1631
1632 // Returns true if this value is exactly 2^N.
1634 bool isPowerOf2(int N) const { return N != INT_MIN && getExactLog2() == N; }
1635
1636 // Returns true if this value is exactly -(2^N).
1638 bool isNegPowerOf2(int N) const {
1639 return N != INT_MIN && isNegative() && getExactLog2Abs() == N;
1640 }
1641
1642 // Returns true if this value is exactly +1.0.
1643 LLVM_READONLY bool isOne() const { return isPowerOf2(0); }
1644
1645 // Returns true if this value is exactly -1.0.
1646 LLVM_READONLY bool isMinusOne() const { return isNegPowerOf2(0); }
1647
1648 LLVM_ABI friend hash_code hash_value(const APFloat &Arg);
1649 friend int ilogb(const APFloat &Arg);
1650 friend APFloat scalbn(APFloat X, int Exp, roundingMode RM);
1651 friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM);
1652 friend IEEEFloat;
1653 friend DoubleAPFloat;
1654};
1655
1656static_assert(sizeof(APFloat) == sizeof(detail::IEEEFloat),
1657 "Empty base class optimization is not performed.");
1658
1659/// See friend declarations above.
1660///
1661/// These additional declarations are required in order to compile LLVM with IBM
1662/// xlC compiler.
1664
1665/// Returns the exponent of the internal representation of the APFloat.
1666///
1667/// Because the radix of APFloat is 2, this is equivalent to floor(log2(x)).
1668/// For special APFloat values, this returns special error codes:
1669///
1670/// NaN -> \c IEK_NaN
1671/// 0 -> \c IEK_Zero
1672/// Inf -> \c IEK_Inf
1673///
1674inline int ilogb(const APFloat &Arg) {
1675 if (APFloat::usesLayout<detail::IEEEFloat>(Arg.getSemantics()))
1676 return ilogb(Arg.U.IEEE);
1677 if (APFloat::usesLayout<detail::DoubleAPFloat>(Arg.getSemantics()))
1678 return ilogb(Arg.U.Double);
1679 llvm_unreachable("Unexpected semantics");
1680}
1681
1682/// Returns: X * 2^Exp for integral exponents.
1684 if (APFloat::usesLayout<detail::IEEEFloat>(X.getSemantics()))
1685 return APFloat(scalbn(X.U.IEEE, Exp, RM), X.getSemantics());
1686 if (APFloat::usesLayout<detail::DoubleAPFloat>(X.getSemantics()))
1687 return APFloat(scalbn(X.U.Double, Exp, RM), X.getSemantics());
1688 llvm_unreachable("Unexpected semantics");
1689}
1690
1691/// Equivalent of C standard library function.
1692///
1693/// While the C standard says Exp is an unspecified value for infinity and nan,
1694/// this returns INT_MAX for infinities, and INT_MIN for NaNs.
1695inline APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM) {
1696 if (APFloat::usesLayout<detail::IEEEFloat>(X.getSemantics()))
1697 return APFloat(frexp(X.U.IEEE, Exp, RM), X.getSemantics());
1698 if (APFloat::usesLayout<detail::DoubleAPFloat>(X.getSemantics()))
1699 return APFloat(frexp(X.U.Double, Exp, RM), X.getSemantics());
1700 llvm_unreachable("Unexpected semantics");
1701}
1702/// Returns the absolute value of the argument.
1704 X.clearSign();
1705 return X;
1706}
1707
1708/// Returns the negated value of the argument.
1710 X.changeSign();
1711 return X;
1712}
1713
1714/// Implements IEEE-754 2008 minNum semantics. Returns the smaller of the
1715/// 2 arguments if both are not NaN. If either argument is a qNaN, returns the
1716/// other argument. If either argument is sNaN, return a qNaN.
1717/// -0 is treated as ordered less than +0.
1719inline APFloat minnum(const APFloat &A, const APFloat &B) {
1720 if (A.isSignaling())
1721 return A.makeQuiet();
1722 if (B.isSignaling())
1723 return B.makeQuiet();
1724 if (A.isNaN())
1725 return B;
1726 if (B.isNaN())
1727 return A;
1728 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1729 return A.isNegative() ? A : B;
1730 return B < A ? B : A;
1731}
1732
1733/// Implements IEEE-754 2008 maxNum semantics. Returns the larger of the
1734/// 2 arguments if both are not NaN. If either argument is a qNaN, returns the
1735/// other argument. If either argument is sNaN, return a qNaN.
1736/// +0 is treated as ordered greater than -0.
1738inline APFloat maxnum(const APFloat &A, const APFloat &B) {
1739 if (A.isSignaling())
1740 return A.makeQuiet();
1741 if (B.isSignaling())
1742 return B.makeQuiet();
1743 if (A.isNaN())
1744 return B;
1745 if (B.isNaN())
1746 return A;
1747 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1748 return A.isNegative() ? B : A;
1749 return A < B ? B : A;
1750}
1751
1752/// Implements IEEE 754-2019 minimum semantics. Returns the smaller of 2
1753/// arguments, returning a quiet NaN if an argument is a NaN and treating -0
1754/// as less than +0.
1756inline APFloat minimum(const APFloat &A, const APFloat &B) {
1757 if (A.isNaN())
1758 return A.makeQuiet();
1759 if (B.isNaN())
1760 return B.makeQuiet();
1761 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1762 return A.isNegative() ? A : B;
1763 return B < A ? B : A;
1764}
1765
1766/// Implements IEEE 754-2019 minimumNumber semantics. Returns the smaller
1767/// of 2 arguments, not propagating NaNs and treating -0 as less than +0.
1769inline APFloat minimumnum(const APFloat &A, const APFloat &B) {
1770 if (A.isNaN())
1771 return B.isNaN() ? B.makeQuiet() : B;
1772 if (B.isNaN())
1773 return A;
1774 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1775 return A.isNegative() ? A : B;
1776 return B < A ? B : A;
1777}
1778
1779/// Implements IEEE 754-2019 maximum semantics. Returns the larger of 2
1780/// arguments, returning a quiet NaN if an argument is a NaN and treating -0
1781/// as less than +0.
1783inline APFloat maximum(const APFloat &A, const APFloat &B) {
1784 if (A.isNaN())
1785 return A.makeQuiet();
1786 if (B.isNaN())
1787 return B.makeQuiet();
1788 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1789 return A.isNegative() ? B : A;
1790 return A < B ? B : A;
1791}
1792
1793/// Implements IEEE 754-2019 maximumNumber semantics. Returns the larger
1794/// of 2 arguments, not propagating NaNs and treating -0 as less than +0.
1796inline APFloat maximumnum(const APFloat &A, const APFloat &B) {
1797 if (A.isNaN())
1798 return B.isNaN() ? B.makeQuiet() : B;
1799 if (B.isNaN())
1800 return A;
1801 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1802 return A.isNegative() ? B : A;
1803 return A < B ? B : A;
1804}
1805
1806/// Implement IEEE 754-2019 exp functions
1808LLVM_ABI std::optional<APFloat>
1809exp(const APFloat &X, RoundingMode RM = APFloat::rmNearestTiesToEven,
1810 APFloat::opStatus *Status = nullptr);
1811
1813 V.print(OS);
1814 return OS;
1815}
1816
1817// We want the following functions to be available in the header for inlining.
1818// We cannot define them inline in the class definition of `DoubleAPFloat`
1819// because doing so would instantiate `std::unique_ptr<APFloat[]>` before
1820// `APFloat` is defined, and that would be undefined behavior.
1821namespace detail {
1822
1824 if (this != &RHS) {
1825 this->~DoubleAPFloat();
1826 new (this) DoubleAPFloat(std::move(RHS));
1827 }
1828 return *this;
1829}
1830
1831APFloat &DoubleAPFloat::getFirst() { return Floats[0]; }
1832const APFloat &DoubleAPFloat::getFirst() const { return Floats[0]; }
1833APFloat &DoubleAPFloat::getSecond() { return Floats[1]; }
1834const APFloat &DoubleAPFloat::getSecond() const { return Floats[1]; }
1835
1836inline DoubleAPFloat::~DoubleAPFloat() { delete[] Floats; }
1837
1838} // namespace detail
1839
1840} // namespace llvm
1841
1842#undef APFLOAT_DISPATCH_ON_SEMANTICS
1843#endif // LLVM_ADT_APFLOAT_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL)
Definition APFloat.h:27
This file implements a class to represent arbitrary precision integral constant values and operations...
#define X(NUM, ENUM, NAME)
Definition ELF.h:856
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:215
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:672
#define LLVM_READONLY
Definition Compiler.h:324
Utilities for dealing with flags related to floating point properties and mode controls.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Load MIR Sample Profile
#define T
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, const llvm::StringTable &StandardNames, VectorLibrary VecLib)
Initialize the set of available library functions based on the specified target triple.
Value * RHS
Value * LHS
The Input class is used to parse a yaml document into in-memory structs and vectors.
static const fltSemantics & IEEEsingle()
Definition APFloat.h:297
static const fltSemantics & Float8E4M3FN()
Definition APFloat.h:307
static LLVM_ABI const llvm::fltSemantics & EnumToSemantics(Semantics S)
Definition APFloat.cpp:123
static LLVM_ABI bool semanticsHasInf(const fltSemantics &)
Definition APFloat.cpp:272
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
Definition APFloat.h:335
static constexpr roundingMode rmTowardZero
Definition APFloat.h:349
static LLVM_ABI ExponentType semanticsMinExponent(const fltSemantics &)
Definition APFloat.cpp:247
llvm::RoundingMode roundingMode
IEEE-754R 4.3: Rounding-direction attributes.
Definition APFloat.h:343
static const fltSemantics & BFloat()
Definition APFloat.h:296
static const fltSemantics & IEEEquad()
Definition APFloat.h:299
static LLVM_ABI unsigned int semanticsSizeInBits(const fltSemantics &)
Definition APFloat.cpp:250
static const fltSemantics & Float8E8M0FNU()
Definition APFloat.h:314
static LLVM_ABI bool semanticsHasSignedRepr(const fltSemantics &)
Definition APFloat.cpp:268
static const fltSemantics & IEEEdouble()
Definition APFloat.h:298
static LLVM_ABI unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
Definition APFloat.cpp:303
static const fltSemantics & x87DoubleExtended()
Definition APFloat.h:318
static constexpr roundingMode rmTowardNegative
Definition APFloat.h:348
uninitializedTag
Convenience enum used to construct an uninitialized APFloat.
Definition APFloat.h:379
static constexpr roundingMode rmNearestTiesToEven
Definition APFloat.h:345
static LLVM_ABI bool isValidArbitraryFPFormat(StringRef Format)
Returns true if the given string is a valid arbitrary floating-point format interpretation for llvm....
Definition APFloat.cpp:6036
static LLVM_ABI bool hasSignBitInMSB(const fltSemantics &)
Definition APFloat.cpp:285
static LLVM_ABI ExponentType semanticsMaxExponent(const fltSemantics &)
Definition APFloat.cpp:243
friend class APFloat
Definition APFloat.h:292
static const fltSemantics & Bogus()
A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real.
Definition APFloat.h:324
static LLVM_ABI unsigned int semanticsPrecision(const fltSemantics &)
Definition APFloat.cpp:239
static LLVM_ABI bool semanticsHasNaN(const fltSemantics &)
Definition APFloat.cpp:276
static LLVM_ABI Semantics SemanticsToEnum(const llvm::fltSemantics &Sem)
Definition APFloat.cpp:170
int32_t ExponentType
A signed type to represent a floating point numbers unbiased exponent.
Definition APFloat.h:156
static constexpr unsigned integerPartWidth
Definition APFloat.h:153
static const fltSemantics & PPCDoubleDoubleLegacy()
Definition APFloat.h:301
APInt::WordType integerPart
Definition APFloat.h:152
static LLVM_ABI bool semanticsHasZero(const fltSemantics &)
Definition APFloat.cpp:264
static LLVM_ABI bool isRepresentableAsNormalIn(const fltSemantics &Src, const fltSemantics &Dst)
Definition APFloat.cpp:289
static const fltSemantics & Float8E5M2FNUZ()
Definition APFloat.h:305
static const fltSemantics & Float8E4M3FNUZ()
Definition APFloat.h:308
static constexpr roundingMode rmTowardPositive
Definition APFloat.h:347
static const fltSemantics & IEEEhalf()
Definition APFloat.h:295
static const fltSemantics & Float4E2M1FN()
Definition APFloat.h:317
static const fltSemantics & Float6E2M3FN()
Definition APFloat.h:316
IlogbErrorKinds
Enumeration of ilogb error results.
Definition APFloat.h:384
static const fltSemantics & Float8E4M3()
Definition APFloat.h:306
static const fltSemantics & Float8E4M3B11FNUZ()
Definition APFloat.h:309
static LLVM_ABI bool isRepresentableBy(const fltSemantics &A, const fltSemantics &B)
Definition APFloat.cpp:215
static const fltSemantics & Float8E3M4()
Definition APFloat.h:312
static LLVM_ABI bool isIEEELikeFP(const fltSemantics &)
Definition APFloat.cpp:280
static const fltSemantics & Float8E5M2()
Definition APFloat.h:304
fltCategory
Category of internally-represented number.
Definition APFloat.h:371
static constexpr roundingMode rmNearestTiesToAway
Definition APFloat.h:350
static const fltSemantics & PPCDoubleDouble()
Definition APFloat.h:300
static const fltSemantics & Float6E3M2FN()
Definition APFloat.h:315
opStatus
IEEE-754R 7: Default exception handling.
Definition APFloat.h:361
static LLVM_ABI unsigned getArbitraryFPFormatSizeInBits(StringRef Format)
Returns the size in bits of a valid arbitrary floating-point format string, or 0 if the string is not...
Definition APFloat.cpp:6020
static LLVM_ABI const fltSemantics * getArbitraryFPSemantics(StringRef Format)
Returns the fltSemantics for a given arbitrary FP format string, or nullptr if invalid.
Definition APFloat.cpp:6040
static const fltSemantics & FloatTF32()
Definition APFloat.h:313
static LLVM_ABI unsigned int semanticsIntSizeInBits(const fltSemantics &, bool)
Definition APFloat.cpp:253
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
Definition APFloat.h:1206
static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for SNaN values.
Definition APFloat.h:1214
LLVM_READONLY bool isNegPowerOf2(int N) const
Definition APFloat.h:1638
opStatus divide(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1294
APFloat & operator=(APFloat &&RHS)=default
bool isFiniteNonZero() const
Definition APFloat.h:1575
APFloat(const APFloat &RHS)=default
void copySign(const APFloat &RHS)
Definition APFloat.h:1388
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition APFloat.cpp:5920
LLVM_READONLY int getExactLog2Abs() const
Definition APFloat.h:1621
opStatus subtract(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1276
bool bitwiseIsEqual(const APFloat &RHS) const
Definition APFloat.h:1530
bool isNegative() const
Definition APFloat.h:1565
~APFloat()=default
LLVM_ABI bool getExactInverse(APFloat *Inv) const
If this value is normal and has an exact, normal, multiplicative inverse, store it in inv and return ...
Definition APFloat.cpp:5862
cmpResult compareAbsoluteValue(const APFloat &RHS) const
Definition APFloat.h:1520
APFloat operator+(const APFloat &RHS) const
Add two APFloats, rounding ties to the nearest even.
Definition APFloat.h:1353
friend DoubleAPFloat
Definition APFloat.h:1653
LLVM_ABI double convertToDouble() const
Converts this APFloat to host double value.
Definition APFloat.cpp:5979
bool isPosInfinity() const
Definition APFloat.h:1578
APFloat(APFloat &&RHS)=default
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
Definition APFloat.h:1602
bool isNormal() const
Definition APFloat.h:1569
bool isDenormal() const
Definition APFloat.h:1566
bool isExactlyValue(double V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
Definition APFloat.h:1548
opStatus add(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1267
LLVM_READONLY int getExactLog2() const
Definition APFloat.h:1628
APFloat(double d)
Definition APFloat.h:1153
APFloat & operator=(const APFloat &RHS)=default
LLVM_READONLY bool isPowerOf2(int N) const
Definition APFloat.h:1634
static LLVM_ABI APFloat getAllOnesValue(const fltSemantics &Semantics)
Returns a float which is bitcasted from an all one value int.
Definition APFloat.cpp:5946
LLVM_ABI friend hash_code hash_value(const APFloat &Arg)
See friend declarations above.
Definition APFloat.cpp:5834
APFloat(const fltSemantics &Semantics, integerPart I)
Definition APFloat.h:1145
bool operator!=(const APFloat &RHS) const
Definition APFloat.h:1486
APFloat(const fltSemantics &Semantics, T V)=delete
const fltSemantics & getSemantics() const
Definition APFloat.h:1573
APFloat operator-(const APFloat &RHS) const
Subtract two APFloats, rounding ties to the nearest even.
Definition APFloat.h:1361
APFloat operator*(const APFloat &RHS) const
Multiply two APFloats, rounding ties to the nearest even.
Definition APFloat.h:1369
APFloat(const fltSemantics &Semantics)
Definition APFloat.h:1143
bool isNonZero() const
Definition APFloat.h:1574
void clearSign()
Definition APFloat.h:1384
bool operator<(const APFloat &RHS) const
Definition APFloat.h:1488
bool isFinite() const
Definition APFloat.h:1570
APFloat makeQuiet() const
Assuming this is an IEEE-754 NaN value, quiet its signaling bit.
Definition APFloat.h:1402
bool isNaN() const
Definition APFloat.h:1563
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
Definition APFloat.h:1433
static APFloat getOne(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative One.
Definition APFloat.h:1174
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
Definition APFloat.h:1555
opStatus multiply(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1285
LLVM_ABI float convertToFloat() const
Converts this APFloat to host float value.
Definition APFloat.cpp:6007
bool isSignaling() const
Definition APFloat.h:1567
bool operator>(const APFloat &RHS) const
Definition APFloat.h:1492
opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend, roundingMode RM)
Definition APFloat.h:1321
APFloat operator/(const APFloat &RHS) const
Divide the first APFloat by the second, rounding ties to the nearest even.
Definition APFloat.h:1377
opStatus remainder(const APFloat &RHS)
Definition APFloat.h:1303
APFloat operator-() const
Negate an APFloat.
Definition APFloat.h:1345
bool isZero() const
Definition APFloat.h:1561
LLVM_READONLY bool isOne() const
Definition APFloat.h:1643
static APFloat getSmallestNormalized(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
Definition APFloat.h:1244
APInt bitcastToAPInt() const
Definition APFloat.h:1457
bool isLargest() const
Definition APFloat.h:1581
friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM)
bool isSmallest() const
Definition APFloat.h:1580
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
Definition APFloat.h:1224
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
Definition APFloat.h:1418
opStatus next(bool nextDown)
Definition APFloat.h:1340
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
Definition APFloat.h:1184
friend APFloat scalbn(APFloat X, int Exp, roundingMode RM)
bool operator>=(const APFloat &RHS) const
Definition APFloat.h:1501
bool needsCleanup() const
Definition APFloat.h:1160
static APFloat getSmallest(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) finite number in the given semantics.
Definition APFloat.h:1234
LLVM_ABI FPClassTest classify() const
Return the FPClassTest which will return true for the value.
Definition APFloat.cpp:5849
bool operator==(const APFloat &RHS) const
Definition APFloat.h:1484
opStatus mod(const APFloat &RHS)
Definition APFloat.h:1312
bool isPosZero() const
Definition APFloat.h:1576
APInt getNaNPayload() const
If the value is a NaN value, return an integer containing the payload of this value.
Definition APFloat.h:1591
friend int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
Definition APFloat.h:1674
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
Fill this APFloat with the result of a string conversion.
Definition APFloat.cpp:5829
fltCategory getCategory() const
Definition APFloat.h:1572
APFloat(const fltSemantics &Semantics, uninitializedTag)
Definition APFloat.h:1150
bool isInteger() const
Definition APFloat.h:1582
bool isNegInfinity() const
Definition APFloat.h:1579
friend IEEEFloat
Definition APFloat.h:1652
LLVM_DUMP_METHOD void dump() const
Definition APFloat.cpp:5957
bool isNegZero() const
Definition APFloat.h:1577
LLVM_ABI void print(raw_ostream &) const
Definition APFloat.cpp:5950
static APFloat copySign(APFloat Value, const APFloat &Sign)
A static helper to produce a copy of an APFloat value with its sign copied from some other APFloat.
Definition APFloat.h:1395
LLVM_READONLY bool isMinusOne() const
Definition APFloat.h:1646
APFloat(float f)
Definition APFloat.h:1154
opStatus roundToIntegral(roundingMode RM)
Definition APFloat.h:1334
void changeSign()
Definition APFloat.h:1383
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Definition APFloat.h:1195
static bool hasSignificand(const fltSemantics &Sem)
Returns true if the given semantics has actual significand.
Definition APFloat.h:1259
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Definition APFloat.h:1165
cmpResult compare(const APFloat &RHS) const
Definition APFloat.h:1508
bool isSmallestNormalized() const
Definition APFloat.h:1584
APFloat(const fltSemantics &Semantics, const APInt &I)
Definition APFloat.h:1152
bool isInfinity() const
Definition APFloat.h:1562
bool operator<=(const APFloat &RHS) const
Definition APFloat.h:1496
Class for arbitrary precision integers.
Definition APInt.h:78
uint64_t WordType
Definition APInt.h:80
static constexpr unsigned APINT_BITS_PER_WORD
Bits in a word.
Definition APInt.h:86
An arbitrary precision integer that knows its signedness.
Definition APSInt.h:24
Tagged union holding either a T or a Error.
Definition Error.h:485
This class is used to gather all the unique data bits of a node.
Definition FoldingSet.h:208
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI void makeSmallestNormalized(bool Neg)
Definition APFloat.cpp:5176
LLVM_ABI DoubleAPFloat & operator=(const DoubleAPFloat &RHS)
Definition APFloat.cpp:4706
LLVM_ABI void changeSign()
Definition APFloat.cpp:5083
LLVM_ABI bool isLargest() const
Definition APFloat.cpp:5650
LLVM_ABI opStatus remainder(const DoubleAPFloat &RHS)
Definition APFloat.cpp:4970
LLVM_ABI opStatus multiply(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4873
LLVM_ABI fltCategory getCategory() const
Definition APFloat.cpp:5142
LLVM_ABI bool bitwiseIsEqual(const DoubleAPFloat &RHS) const
Definition APFloat.cpp:5199
LLVM_ABI LLVM_READONLY int getExactLog2Abs() const
Definition APFloat.cpp:5674
LLVM_ABI opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
Definition APFloat.cpp:5601
LLVM_ABI APInt bitcastToAPInt() const
Definition APFloat.cpp:5210
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
Definition APFloat.cpp:5220
LLVM_ABI bool isSmallest() const
Definition APFloat.cpp:5633
LLVM_ABI opStatus subtract(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4865
LLVM_ABI friend hash_code hash_value(const DoubleAPFloat &Arg)
Definition APFloat.cpp:5204
LLVM_ABI cmpResult compareAbsoluteValue(const DoubleAPFloat &RHS) const
Definition APFloat.cpp:5089
LLVM_ABI bool isDenormal() const
Definition APFloat.cpp:5626
LLVM_ABI opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
Definition APFloat.cpp:5437
LLVM_ABI void makeSmallest(bool Neg)
Definition APFloat.cpp:5169
LLVM_ABI friend int ilogb(const DoubleAPFloat &X)
Definition APFloat.cpp:5683
LLVM_ABI opStatus next(bool nextDown)
Definition APFloat.cpp:5236
LLVM_ABI void makeInf(bool Neg)
Definition APFloat.cpp:5148
LLVM_ABI bool isInteger() const
Definition APFloat.cpp:5658
LLVM_ABI void makeZero(bool Neg)
Definition APFloat.cpp:5153
LLVM_ABI opStatus divide(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4959
LLVM_ABI bool isSmallestNormalized() const
Definition APFloat.cpp:5641
LLVM_ABI opStatus mod(const DoubleAPFloat &RHS)
Definition APFloat.cpp:4980
LLVM_ABI DoubleAPFloat(const fltSemantics &S)
Definition APFloat.cpp:4653
LLVM_ABI void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision, unsigned FormatMaxPadding, bool TruncateZero=true) const
Definition APFloat.cpp:5664
LLVM_ABI void makeLargest(bool Neg)
Definition APFloat.cpp:5158
LLVM_ABI cmpResult compare(const DoubleAPFloat &RHS) const
Definition APFloat.cpp:5191
LLVM_ABI friend DoubleAPFloat scalbn(const DoubleAPFloat &X, int Exp, roundingMode)
LLVM_ABI opStatus roundToIntegral(roundingMode RM)
Definition APFloat.cpp:5006
LLVM_ABI opStatus fusedMultiplyAdd(const DoubleAPFloat &Multiplicand, const DoubleAPFloat &Addend, roundingMode RM)
Definition APFloat.cpp:4991
LLVM_ABI APInt getNaNPayload() const
Definition APFloat.cpp:5812
LLVM_ABI unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
Definition APFloat.cpp:5616
bool needsCleanup() const
Definition APFloat.h:884
LLVM_ABI bool isNegative() const
Definition APFloat.cpp:5146
LLVM_ABI opStatus add(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4860
LLVM_ABI friend DoubleAPFloat frexp(const DoubleAPFloat &X, int &Exp, roundingMode)
LLVM_ABI void makeNaN(bool SNaN, bool Neg, const APInt *fill)
Definition APFloat.cpp:5186
LLVM_ABI unsigned int convertToHexString(char *dst, unsigned int hexDigits, bool upperCase, roundingMode) const
Write out a hexadecimal representation of the floating point value to DST, which must be of sufficien...
Definition APFloat.cpp:3201
LLVM_ABI cmpResult compareAbsoluteValue(const IEEEFloat &) const
Definition APFloat.cpp:1450
LLVM_ABI opStatus mod(const IEEEFloat &)
C fmod, or llvm frem.
Definition APFloat.cpp:2206
fltCategory getCategory() const
Definition APFloat.h:589
LLVM_ABI opStatus convertFromAPInt(const APInt &, bool, roundingMode)
Definition APFloat.cpp:2761
LLVM_ABI APInt getNaNPayload() const
Definition APFloat.cpp:4541
bool isNonZero() const
Definition APFloat.h:591
bool isFiniteNonZero() const
Definition APFloat.h:592
bool needsCleanup() const
Returns whether this instance allocated memory.
Definition APFloat.h:479
LLVM_ABI void makeLargest(bool Neg=false)
Make this number the largest magnitude normal number in the given semantics.
Definition APFloat.cpp:3968
LLVM_ABI LLVM_READONLY int getExactLog2Abs() const
Definition APFloat.cpp:4363
LLVM_ABI APInt bitcastToAPInt() const
Definition APFloat.cpp:3597
LLVM_ABI friend IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
Definition APFloat.cpp:4613
LLVM_ABI cmpResult compare(const IEEEFloat &) const
IEEE comparison with another floating point number (NaNs compare unordered, 0==-0).
Definition APFloat.cpp:2374
bool isNegative() const
IEEE-754R isSignMinus: Returns true if and only if the current value is negative.
Definition APFloat.h:554
LLVM_ABI opStatus divide(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2080
LLVM_ABI friend hash_code hash_value(const IEEEFloat &Arg)
Overload to compute a hash code for an APFloat value.
Definition APFloat.cpp:3341
bool isNaN() const
Returns true if and only if the float is a quiet or signaling NaN.
Definition APFloat.h:579
LLVM_ABI opStatus remainder(const IEEEFloat &)
IEEE remainder.
Definition APFloat.cpp:2098
LLVM_ABI double convertToDouble() const
Definition APFloat.cpp:3667
LLVM_ABI float convertToFloat() const
Definition APFloat.cpp:3660
LLVM_ABI opStatus subtract(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2056
LLVM_ABI void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
Converts this value into a decimal string.
Definition APFloat.cpp:4319
LLVM_ABI void makeSmallest(bool Neg=false)
Make this number the smallest magnitude denormal number in the given semantics.
Definition APFloat.cpp:4000
LLVM_ABI void makeInf(bool Neg=false)
Definition APFloat.cpp:4560
bool isNormal() const
IEEE-754R isNormal: Returns true if and only if the current value is normal.
Definition APFloat.h:560
LLVM_ABI bool isSmallestNormalized() const
Returns true if this is the smallest (by magnitude) normalized finite number in the given semantics.
Definition APFloat.cpp:971
friend class IEEEFloatUnitTestHelper
Definition APFloat.h:834
LLVM_ABI void makeQuiet()
Definition APFloat.cpp:4589
LLVM_ABI bool isLargest() const
Returns true if and only if the number has the largest possible finite magnitude in the current seman...
Definition APFloat.cpp:1073
LLVM_ABI opStatus add(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2050
bool isFinite() const
Returns true if and only if the current value is zero, subnormal, or normal.
Definition APFloat.h:566
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
Definition APFloat.cpp:3144
LLVM_ABI void makeNaN(bool SNaN=false, bool Neg=false, const APInt *fill=nullptr)
Definition APFloat.cpp:859
LLVM_ABI opStatus multiply(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2062
LLVM_ABI opStatus roundToIntegral(roundingMode)
Definition APFloat.cpp:2289
LLVM_ABI IEEEFloat & operator=(const IEEEFloat &)
Definition APFloat.cpp:931
LLVM_ABI bool bitwiseIsEqual(const IEEEFloat &) const
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
Definition APFloat.cpp:1098
LLVM_ABI void makeSmallestNormalized(bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
Definition APFloat.cpp:4014
LLVM_ABI bool isInteger() const
Returns true if and only if the number is an exact integer.
Definition APFloat.cpp:1090
bool isPosZero() const
Definition APFloat.h:593
LLVM_ABI IEEEFloat(const fltSemantics &)
Definition APFloat.cpp:1125
LLVM_ABI opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2243
LLVM_ABI friend int ilogb(const IEEEFloat &Arg)
Definition APFloat.cpp:4595
LLVM_ABI opStatus next(bool nextDown)
IEEE-754R 5.3.1: nextUp/nextDown.
Definition APFloat.cpp:4408
bool isInfinity() const
IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
Definition APFloat.h:576
const fltSemantics & getSemantics() const
Definition APFloat.h:590
bool isZero() const
Returns true if and only if the float is plus or minus zero.
Definition APFloat.h:569
LLVM_ABI bool isSignaling() const
Returns true if and only if the float is a signaling NaN.
Definition APFloat.cpp:4392
bool operator==(const IEEEFloat &) const =delete
The definition of equality is not straightforward for floating point, so we won't use operator==.
LLVM_ABI void makeZero(bool Neg=false)
Definition APFloat.cpp:4575
LLVM_ABI opStatus convert(const fltSemantics &, roundingMode, bool *)
IEEEFloat::convert - convert a value of one floating point type to another.
Definition APFloat.cpp:2450
LLVM_ABI void changeSign()
Definition APFloat.cpp:2008
LLVM_ABI bool isDenormal() const
IEEE-754R isSubnormal(): Returns true if and only if the float is a denormal.
Definition APFloat.cpp:956
LLVM_ABI opStatus convertToInteger(MutableArrayRef< integerPart >, unsigned int, bool, roundingMode, bool *) const
Definition APFloat.cpp:2706
LLVM_ABI friend IEEEFloat frexp(const IEEEFloat &X, int &Exp, roundingMode)
Definition APFloat.cpp:4634
LLVM_ABI bool isSmallest() const
Returns true if and only if the number has the smallest possible non-zero magnitude in the current se...
Definition APFloat.cpp:963
bool isNegZero() const
Definition APFloat.h:594
An opaque object representing a hash code.
Definition Hashing.h:77
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static constexpr opStatus opInexact
Definition APFloat.h:455
static constexpr fltCategory fcNaN
Definition APFloat.h:457
static constexpr opStatus opDivByZero
Definition APFloat.h:452
static constexpr opStatus opOverflow
Definition APFloat.h:453
static constexpr cmpResult cmpLessThan
Definition APFloat.h:447
static constexpr roundingMode rmTowardPositive
Definition APFloat.h:443
static constexpr uninitializedTag uninitialized
Definition APFloat.h:437
static constexpr fltCategory fcZero
Definition APFloat.h:459
static constexpr opStatus opOK
Definition APFloat.h:450
static constexpr cmpResult cmpGreaterThan
Definition APFloat.h:448
static constexpr unsigned integerPartWidth
Definition APFloat.h:445
LLVM_ABI hash_code hash_value(const IEEEFloat &Arg)
Definition APFloat.cpp:3341
APFloatBase::ExponentType ExponentType
Definition APFloat.h:436
APFloatBase::fltCategory fltCategory
Definition APFloat.h:435
static constexpr fltCategory fcNormal
Definition APFloat.h:458
static constexpr opStatus opInvalidOp
Definition APFloat.h:451
APFloatBase::opStatus opStatus
Definition APFloat.h:433
LLVM_ABI IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM)
Definition APFloat.cpp:4634
APFloatBase::uninitializedTag uninitializedTag
Definition APFloat.h:431
static constexpr cmpResult cmpUnordered
Definition APFloat.h:449
static constexpr roundingMode rmTowardNegative
Definition APFloat.h:442
APFloatBase::roundingMode roundingMode
Definition APFloat.h:432
APFloatBase::cmpResult cmpResult
Definition APFloat.h:434
static constexpr fltCategory fcInfinity
Definition APFloat.h:456
static constexpr roundingMode rmNearestTiesToAway
Definition APFloat.h:440
static constexpr roundingMode rmTowardZero
Definition APFloat.h:444
static constexpr opStatus opUnderflow
Definition APFloat.h:454
static constexpr roundingMode rmNearestTiesToEven
Definition APFloat.h:438
LLVM_ABI int ilogb(const IEEEFloat &Arg)
Definition APFloat.cpp:4595
static constexpr cmpResult cmpEqual
Definition APFloat.h:446
LLVM_ABI IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
Definition APFloat.cpp:4613
APFloatBase::integerPart integerPart
Definition APFloat.h:430
This is an optimization pass for GlobalISel generic memory operations.
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1759
hash_code hash_value(const FixedPointSemantics &Val)
static constexpr APFloatBase::ExponentType exponentZero(const fltSemantics &semantics)
Definition APFloat.cpp:308
APFloat abs(APFloat X)
Returns the absolute value of the argument.
Definition APFloat.h:1703
LLVM_READONLY APFloat maximum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 maximum semantics.
Definition APFloat.h:1783
static void assign(DXContainerYAML::SourceInfo::SectionHeader &Dst, const dxbc::SourceInfo::SectionHeader &Src)
int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
Definition APFloat.h:1674
APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM)
Equivalent of C standard library function.
Definition APFloat.h:1695
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE-754 2008 maxNum semantics.
Definition APFloat.h:1738
lostFraction
Enum that represents what fraction of the LSB truncated bits of an fp number represent.
Definition APFloat.h:51
@ lfMoreThanHalf
Definition APFloat.h:55
@ lfLessThanHalf
Definition APFloat.h:53
@ lfExactlyHalf
Definition APFloat.h:54
@ lfExactlyZero
Definition APFloat.h:52
LLVM_READONLY LLVM_ABI std::optional< APFloat > exp(const APFloat &X, RoundingMode RM=APFloat::rmNearestTiesToEven, APFloat::opStatus *Status=nullptr)
Implement IEEE 754-2019 exp functions.
Definition APFloat.cpp:6137
LLVM_READONLY APFloat minimumnum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 minimumNumber semantics.
Definition APFloat.h:1769
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
APFloat scalbn(APFloat X, int Exp, APFloat::roundingMode RM)
Returns: X * 2^Exp for integral exponents.
Definition APFloat.h:1683
static constexpr APFloatBase::ExponentType exponentNaN(const fltSemantics &semantics)
Definition APFloat.cpp:318
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE-754 2008 minNum semantics.
Definition APFloat.h:1719
fltNonfiniteBehavior
Definition APFloat.h:959
RoundingMode
Rounding mode.
@ TowardZero
roundTowardZero.
@ NearestTiesToEven
roundTiesToEven.
@ TowardPositive
roundTowardPositive.
@ NearestTiesToAway
roundTiesToAway.
@ TowardNegative
roundTowardNegative.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
static constexpr APFloatBase::ExponentType exponentInf(const fltSemantics &semantics)
Definition APFloat.cpp:313
APFloat neg(APFloat X)
Returns the negated value of the argument.
Definition APFloat.h:1709
LLVM_READONLY APFloat minimum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 minimum semantics.
Definition APFloat.h:1756
LLVM_READONLY APFloat maximumnum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 maximumNumber semantics.
Definition APFloat.h:1796
fltNanEncoding
Definition APFloat.h:983
#define N
APFloatBase::ExponentType maxExponent
Definition APFloat.h:1008
fltNonfiniteBehavior nonFiniteBehavior
Definition APFloat.h:1021
APFloatBase::ExponentType minExponent
Definition APFloat.h:1012
unsigned int sizeInBits
Definition APFloat.h:1019
unsigned int precision
Definition APFloat.h:1016
fltNanEncoding nanEncoding
Definition APFloat.h:1023
bool hasExplicitIntegerBit
Definition APFloat.h:1051