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