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
680 APInt getNaNPayload() const;
681
682private:
683 /// \name Simple Queries
684 /// @{
685
686 integerPart *significandParts();
687 const integerPart *significandParts() const;
688 LLVM_ABI unsigned int partCount() const;
689
690 /// @}
691
692 /// \name Significand operations.
693 /// @{
694
695 integerPart addSignificand(const IEEEFloat &);
696 integerPart subtractSignificand(const IEEEFloat &, integerPart);
697 // Exported for IEEEFloatUnitTestHelper.
698 LLVM_ABI lostFraction addOrSubtractSignificand(const IEEEFloat &,
699 bool subtract);
700 lostFraction multiplySignificand(const IEEEFloat &, IEEEFloat,
701 bool ignoreAddend = false);
702 lostFraction multiplySignificand(const IEEEFloat&);
703 lostFraction divideSignificand(const IEEEFloat &);
704 void incrementSignificand();
705 void initialize(const fltSemantics *);
706 void shiftSignificandLeft(unsigned int);
707 lostFraction shiftSignificandRight(unsigned int);
708 unsigned int significandLSB() const;
709 unsigned int significandMSB() const;
710 void zeroSignificand();
711 unsigned int getNumHighBits() const;
712 /// Return true if the significand excluding the integral bit is all ones.
713 bool isSignificandAllOnes() const;
714 bool isSignificandAllOnesExceptLSB() const;
715 /// Return true if the significand excluding the integral bit is all zeros.
716 bool isSignificandAllZeros() const;
717 bool isSignificandAllZerosExceptMSB() const;
718
719 /// @}
720
721 /// \name Arithmetic on special values.
722 /// @{
723
724 opStatus addOrSubtractSpecials(const IEEEFloat &, bool subtract);
725 opStatus divideSpecials(const IEEEFloat &);
726 opStatus multiplySpecials(const IEEEFloat &);
727 opStatus modSpecials(const IEEEFloat &);
728 opStatus remainderSpecials(const IEEEFloat&);
729
730 /// @}
731
732 /// \name Miscellany
733 /// @{
734
735 bool convertFromStringSpecials(StringRef str);
737 opStatus addOrSubtract(const IEEEFloat &, roundingMode, bool subtract);
738 opStatus handleOverflow(roundingMode);
739 bool roundAwayFromZero(roundingMode, lostFraction, unsigned int) const;
740 opStatus convertToSignExtendedInteger(MutableArrayRef<integerPart>,
741 unsigned int, bool, roundingMode,
742 bool *) const;
743 opStatus convertFromUnsignedParts(const integerPart *, unsigned int,
745 Expected<opStatus> convertFromHexadecimalString(StringRef, roundingMode);
746 Expected<opStatus> convertFromDecimalString(StringRef, roundingMode);
747 char *convertNormalToHexString(char *, unsigned int, bool,
748 roundingMode) const;
749 opStatus roundSignificandWithExponent(const integerPart *, unsigned int, int,
754
755 /// @}
756
757 template <const fltSemantics &S> APInt convertIEEEFloatToAPInt() const;
758 APInt convertHalfAPFloatToAPInt() const;
759 APInt convertBFloatAPFloatToAPInt() const;
760 APInt convertFloatAPFloatToAPInt() const;
761 APInt convertDoubleAPFloatToAPInt() const;
762 APInt convertQuadrupleAPFloatToAPInt() const;
763 APInt convertF80LongDoubleAPFloatToAPInt() const;
764 APInt convertPPCDoubleDoubleLegacyAPFloatToAPInt() const;
765 APInt convertFloat8E5M2APFloatToAPInt() const;
766 APInt convertFloat8E5M2FNUZAPFloatToAPInt() const;
767 APInt convertFloat8E4M3APFloatToAPInt() const;
768 APInt convertFloat8E4M3FNAPFloatToAPInt() const;
769 APInt convertFloat8E4M3FNUZAPFloatToAPInt() const;
770 APInt convertFloat8E4M3B11FNUZAPFloatToAPInt() const;
771 APInt convertFloat8E3M4APFloatToAPInt() const;
772 APInt convertFloatTF32APFloatToAPInt() const;
773 APInt convertFloat8E8M0FNUAPFloatToAPInt() const;
774 APInt convertFloat6E3M2FNAPFloatToAPInt() const;
775 APInt convertFloat6E2M3FNAPFloatToAPInt() const;
776 APInt convertFloat4E2M1FNAPFloatToAPInt() const;
777 void initFromAPInt(const fltSemantics *Sem, const APInt &api);
778 template <const fltSemantics &S> void initFromIEEEAPInt(const APInt &api);
779 void initFromHalfAPInt(const APInt &api);
780 void initFromBFloatAPInt(const APInt &api);
781 void initFromFloatAPInt(const APInt &api);
782 void initFromDoubleAPInt(const APInt &api);
783 void initFromQuadrupleAPInt(const APInt &api);
784 void initFromF80LongDoubleAPInt(const APInt &api);
785 void initFromPPCDoubleDoubleLegacyAPInt(const APInt &api);
786 void initFromFloat8E5M2APInt(const APInt &api);
787 void initFromFloat8E5M2FNUZAPInt(const APInt &api);
788 void initFromFloat8E4M3APInt(const APInt &api);
789 void initFromFloat8E4M3FNAPInt(const APInt &api);
790 void initFromFloat8E4M3FNUZAPInt(const APInt &api);
791 void initFromFloat8E4M3B11FNUZAPInt(const APInt &api);
792 void initFromFloat8E3M4APInt(const APInt &api);
793 void initFromFloatTF32APInt(const APInt &api);
794 void initFromFloat8E8M0FNUAPInt(const APInt &api);
795 void initFromFloat6E3M2FNAPInt(const APInt &api);
796 void initFromFloat6E2M3FNAPInt(const APInt &api);
797 void initFromFloat4E2M1FNAPInt(const APInt &api);
798
799 void assign(const IEEEFloat &);
800 void copySignificand(const IEEEFloat &);
801 void freeSignificand();
802
803 /// Note: this must be the first data member.
804 /// The semantics that this value obeys.
805 const fltSemantics *semantics;
806
807 /// A binary fraction with an explicit integer bit.
808 ///
809 /// The significand must be at least one bit wider than the target precision.
810 union Significand {
811 integerPart part;
812 integerPart *parts;
813 } significand;
814
815 /// The signed unbiased exponent of the value.
816 ExponentType exponent;
817
818 /// What kind of floating point number this is.
819 ///
820 /// Only 2 bits are required, but VisualStudio incorrectly sign extends it.
821 /// Using the extra bit keeps it from failing under VisualStudio.
822 fltCategory category : 3;
823
824 /// Sign bit of the number.
825 unsigned int sign : 1;
826
828};
829
831LLVM_ABI int ilogb(const IEEEFloat &Arg);
833LLVM_ABI IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM);
834
835// This mode implements more precise float in terms of two APFloats.
836// The interface and layout is designed for arbitrary underlying semantics,
837// though currently only PPCDoubleDouble semantics are supported, whose
838// corresponding underlying semantics are IEEEdouble.
839class DoubleAPFloat final {
840 // Note: this must be the first data member.
841 const fltSemantics *Semantics;
842 APFloat *Floats;
843
844 opStatus addImpl(const APFloat &a, const APFloat &aa, const APFloat &c,
845 const APFloat &cc, roundingMode RM);
846
847 opStatus addWithSpecial(const DoubleAPFloat &LHS, const DoubleAPFloat &RHS,
848 DoubleAPFloat &Out, roundingMode RM);
849 opStatus convertToSignExtendedInteger(MutableArrayRef<integerPart> Input,
850 unsigned int Width, bool IsSigned,
851 roundingMode RM, bool *IsExact) const;
852
853 // Convert an unsigned integer Src to a floating point number,
854 // rounding according to RM. The sign of the floating point number is not
855 // modified.
856 opStatus convertFromUnsignedParts(const integerPart *Src,
857 unsigned int SrcCount, roundingMode RM);
858
859 // Handle overflow. Sign is preserved. We either become infinity or
860 // the largest finite number.
861 opStatus handleOverflow(roundingMode RM);
862
863public:
867 LLVM_ABI DoubleAPFloat(const fltSemantics &S, const APInt &I);
869 APFloat &&Second);
873
876
877 bool needsCleanup() const { return Floats != nullptr; }
878
879 inline APFloat &getFirst();
880 inline const APFloat &getFirst() const;
881 inline APFloat &getSecond();
882 inline const APFloat &getSecond() const;
883
891 const DoubleAPFloat &Addend,
892 roundingMode RM);
894 LLVM_ABI void changeSign();
896
898 LLVM_ABI bool isNegative() const;
899
900 LLVM_ABI void makeInf(bool Neg);
901 LLVM_ABI void makeZero(bool Neg);
902 LLVM_ABI void makeLargest(bool Neg);
903 LLVM_ABI void makeSmallest(bool Neg);
904 LLVM_ABI void makeSmallestNormalized(bool Neg);
905 LLVM_ABI void makeNaN(bool SNaN, bool Neg, const APInt *fill);
906
908 LLVM_ABI bool bitwiseIsEqual(const DoubleAPFloat &RHS) const;
911 LLVM_ABI opStatus next(bool nextDown);
912
914 unsigned int Width, bool IsSigned,
915 roundingMode RM, bool *IsExact) const;
916 LLVM_ABI opStatus convertFromAPInt(const APInt &Input, bool IsSigned,
917 roundingMode RM);
918 LLVM_ABI unsigned int convertToHexString(char *DST, unsigned int HexDigits,
919 bool UpperCase,
920 roundingMode RM) const;
921
922 LLVM_ABI bool isDenormal() const;
923 LLVM_ABI bool isSmallest() const;
924 LLVM_ABI bool isSmallestNormalized() const;
925 LLVM_ABI bool isLargest() const;
926 LLVM_ABI bool isInteger() const;
927
928 APInt getNaNPayload() const;
929
930 LLVM_ABI void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision,
931 unsigned FormatMaxPadding,
932 bool TruncateZero = true) const;
933
935
936 LLVM_ABI friend int ilogb(const DoubleAPFloat &X);
939 LLVM_ABI friend DoubleAPFloat frexp(const DoubleAPFloat &X, int &Exp,
941 LLVM_ABI friend hash_code hash_value(const DoubleAPFloat &Arg);
942};
943
945LLVM_ABI DoubleAPFloat scalbn(const DoubleAPFloat &Arg, int Exp,
946 roundingMode RM);
948
949} // End detail namespace
950
951// How the nonfinite values Inf and NaN are represented.
953 // Represents standard IEEE 754 behavior. A value is nonfinite if the
954 // exponent field is all 1s. In such cases, a value is Inf if the
955 // significand bits are all zero, and NaN otherwise
957
958 // This behavior is present in the Float8ExMyFN* types (Float8E4M3FN,
959 // Float8E5M2FNUZ, Float8E4M3FNUZ, and Float8E4M3B11FNUZ). There is no
960 // representation for Inf, and operations that would ordinarily produce Inf
961 // produce NaN instead.
962 // The details of the NaN representation(s) in this form are determined by the
963 // `fltNanEncoding` enum. We treat all NaNs as quiet, as the available
964 // encodings do not distinguish between signalling and quiet NaN.
966
967 // This behavior is present in Float6E3M2FN, Float6E2M3FN, and
968 // Float4E2M1FN types, which do not support Inf or NaN values.
970};
971
972// How NaN values are represented. This is curently only used in combination
973// with fltNonfiniteBehavior::NanOnly, and using a variant other than IEEE
974// while having IEEE non-finite behavior is liable to lead to unexpected
975// results.
976enum class fltNanEncoding {
977 // Represents the standard IEEE behavior where a value is NaN if its
978 // exponent is all 1s and the significand is non-zero.
980
981 // Represents the behavior in the Float8E4M3FN floating point type where NaN
982 // is represented by having the exponent and mantissa set to all 1s.
983 // This behavior matches the FP8 E4M3 type described in
984 // https://arxiv.org/abs/2209.05433. We treat both signed and unsigned NaNs
985 // as non-signalling, although the paper does not state whether the NaN
986 // values are signalling or not.
988
989 // Represents the behavior in Float8E{5,4}E{2,3}FNUZ floating point types
990 // where NaN is represented by a sign bit of 1 and all 0s in the exponent
991 // and mantissa (i.e. the negative zero encoding in a IEEE float). Since
992 // there is only one NaN value, it is treated as quiet NaN. This matches the
993 // behavior described in https://arxiv.org/abs/2206.02915 .
995};
996/* Represents floating point arithmetic semantics. */
998 /* The largest E such that 2^E is representable; this matches the
999 definition of IEEE 754. */
1001
1002 /* The smallest E such that 2^E is a normalized number; this
1003 matches the definition of IEEE 754. */
1005
1006 /* Number of bits in the significand. This includes the integer
1007 bit. */
1008 unsigned int precision;
1009
1010 /* Number of bits actually used in the semantics. */
1011 unsigned int sizeInBits;
1012
1014
1016
1017 /* Whether this semantics has an encoding for Zero */
1018 bool hasZero = true;
1019
1020 /* Whether this semantics can represent signed values */
1021 bool hasSignedRepr = true;
1022
1023 /* Whether the sign bit of this semantics is the most significant bit */
1024 bool hasSignBitInMSB = true;
1025};
1026
1027// This is a interface class that is currently forwarding functionalities from
1028// detail::IEEEFloat.
1029class APFloat : public APFloatBase {
1030 using IEEEFloat = detail::IEEEFloat;
1031 using DoubleAPFloat = detail::DoubleAPFloat;
1032
1033 static_assert(std::is_standard_layout<IEEEFloat>::value);
1034
1035 union Storage {
1036 const fltSemantics *semantics;
1037 IEEEFloat IEEE;
1038 DoubleAPFloat Double;
1039
1040 LLVM_ABI explicit Storage(IEEEFloat F, const fltSemantics &S);
1041 explicit Storage(DoubleAPFloat F, const fltSemantics &S)
1042 : Double(std::move(F)) {
1043 assert(&S == &PPCDoubleDouble());
1044 }
1045
1046 template <typename... ArgTypes>
1047 Storage(const fltSemantics &Semantics, ArgTypes &&... Args) {
1048 if (usesLayout<IEEEFloat>(Semantics)) {
1049 new (&IEEE) IEEEFloat(Semantics, std::forward<ArgTypes>(Args)...);
1050 return;
1051 }
1052 if (usesLayout<DoubleAPFloat>(Semantics)) {
1053 new (&Double) DoubleAPFloat(Semantics, std::forward<ArgTypes>(Args)...);
1054 return;
1055 }
1056 llvm_unreachable("Unexpected semantics");
1057 }
1058
1059 LLVM_ABI ~Storage();
1060 LLVM_ABI Storage(const Storage &RHS);
1061 LLVM_ABI Storage(Storage &&RHS);
1062 LLVM_ABI Storage &operator=(const Storage &RHS);
1063 LLVM_ABI Storage &operator=(Storage &&RHS);
1064 } U;
1065
1066 template <typename T> static bool usesLayout(const fltSemantics &Semantics) {
1067 static_assert(std::is_same<T, IEEEFloat>::value ||
1068 std::is_same<T, DoubleAPFloat>::value);
1069 if (std::is_same<T, DoubleAPFloat>::value) {
1070 return &Semantics == &PPCDoubleDouble();
1071 }
1072 return &Semantics != &PPCDoubleDouble();
1073 }
1074
1075 IEEEFloat &getIEEE() {
1076 if (usesLayout<IEEEFloat>(*U.semantics))
1077 return U.IEEE;
1078 if (usesLayout<DoubleAPFloat>(*U.semantics))
1079 return U.Double.getFirst().U.IEEE;
1080 llvm_unreachable("Unexpected semantics");
1081 }
1082
1083 const IEEEFloat &getIEEE() const {
1084 if (usesLayout<IEEEFloat>(*U.semantics))
1085 return U.IEEE;
1086 if (usesLayout<DoubleAPFloat>(*U.semantics))
1087 return U.Double.getFirst().U.IEEE;
1088 llvm_unreachable("Unexpected semantics");
1089 }
1090
1091 void makeZero(bool Neg) { APFLOAT_DISPATCH_ON_SEMANTICS(makeZero(Neg)); }
1092
1093 void makeInf(bool Neg) { APFLOAT_DISPATCH_ON_SEMANTICS(makeInf(Neg)); }
1094
1095 void makeNaN(bool SNaN, bool Neg, const APInt *fill) {
1096 APFLOAT_DISPATCH_ON_SEMANTICS(makeNaN(SNaN, Neg, fill));
1097 }
1098
1099 void makeLargest(bool Neg) {
1100 APFLOAT_DISPATCH_ON_SEMANTICS(makeLargest(Neg));
1101 }
1102
1103 void makeSmallest(bool Neg) {
1104 APFLOAT_DISPATCH_ON_SEMANTICS(makeSmallest(Neg));
1105 }
1106
1107 void makeSmallestNormalized(bool Neg) {
1108 APFLOAT_DISPATCH_ON_SEMANTICS(makeSmallestNormalized(Neg));
1109 }
1110
1111 explicit APFloat(IEEEFloat F, const fltSemantics &S) : U(std::move(F), S) {}
1112 explicit APFloat(DoubleAPFloat F, const fltSemantics &S)
1113 : U(std::move(F), S) {}
1114
1115public:
1119 template <typename T,
1120 typename = std::enable_if_t<std::is_floating_point<T>::value>>
1121 APFloat(const fltSemantics &Semantics, T V) = delete;
1122 // TODO: Remove this constructor. This isn't faster than the first one.
1126 explicit APFloat(double d) : U(IEEEFloat(d), IEEEdouble()) {}
1127 explicit APFloat(float f) : U(IEEEFloat(f), IEEEsingle()) {}
1128 APFloat(const APFloat &RHS) = default;
1129 APFloat(APFloat &&RHS) = default;
1130
1131 ~APFloat() = default;
1132
1134
1135 /// Factory for Positive and Negative Zero.
1136 ///
1137 /// \param Negative True iff the number should be negative.
1138 static APFloat getZero(const fltSemantics &Sem, bool Negative = false) {
1139 APFloat Val(Sem, uninitialized);
1140 Val.makeZero(Negative);
1141 return Val;
1142 }
1143
1144 /// Factory for Positive and Negative One.
1145 ///
1146 /// \param Negative True iff the number should be negative.
1147 static APFloat getOne(const fltSemantics &Sem, bool Negative = false) {
1148 APFloat Val(Sem, 1U);
1149 if (Negative)
1150 Val.changeSign();
1151 return Val;
1152 }
1153
1154 /// Factory for Positive and Negative Infinity.
1155 ///
1156 /// \param Negative True iff the number should be negative.
1157 static APFloat getInf(const fltSemantics &Sem, bool Negative = false) {
1158 APFloat Val(Sem, uninitialized);
1159 Val.makeInf(Negative);
1160 return Val;
1161 }
1162
1163 /// Factory for NaN values.
1164 ///
1165 /// \param Negative - True iff the NaN generated should be negative.
1166 /// \param payload - The unspecified fill bits for creating the NaN, 0 by
1167 /// default. The value is truncated as necessary.
1168 static APFloat getNaN(const fltSemantics &Sem, bool Negative = false,
1169 uint64_t payload = 0) {
1170 if (payload) {
1171 APInt intPayload(64, payload);
1172 return getQNaN(Sem, Negative, &intPayload);
1173 } else {
1174 return getQNaN(Sem, Negative, nullptr);
1175 }
1176 }
1177
1178 /// Factory for QNaN values.
1179 static APFloat getQNaN(const fltSemantics &Sem, bool Negative = false,
1180 const APInt *payload = nullptr) {
1181 APFloat Val(Sem, uninitialized);
1182 Val.makeNaN(false, Negative, payload);
1183 return Val;
1184 }
1185
1186 /// Factory for SNaN values.
1187 static APFloat getSNaN(const fltSemantics &Sem, bool Negative = false,
1188 const APInt *payload = nullptr) {
1189 APFloat Val(Sem, uninitialized);
1190 Val.makeNaN(true, Negative, payload);
1191 return Val;
1192 }
1193
1194 /// Returns the largest finite number in the given semantics.
1195 ///
1196 /// \param Negative - True iff the number should be negative
1197 static APFloat getLargest(const fltSemantics &Sem, bool Negative = false) {
1198 APFloat Val(Sem, uninitialized);
1199 Val.makeLargest(Negative);
1200 return Val;
1201 }
1202
1203 /// Returns the smallest (by magnitude) finite number in the given semantics.
1204 /// Might be denormalized, which implies a relative loss of precision.
1205 ///
1206 /// \param Negative - True iff the number should be negative
1207 static APFloat getSmallest(const fltSemantics &Sem, bool Negative = false) {
1208 APFloat Val(Sem, uninitialized);
1209 Val.makeSmallest(Negative);
1210 return Val;
1211 }
1212
1213 /// Returns the smallest (by magnitude) normalized finite number in the given
1214 /// semantics.
1215 ///
1216 /// \param Negative - True iff the number should be negative
1217 static APFloat getSmallestNormalized(const fltSemantics &Sem,
1218 bool Negative = false) {
1219 APFloat Val(Sem, uninitialized);
1220 Val.makeSmallestNormalized(Negative);
1221 return Val;
1222 }
1223
1224 /// Returns a float which is bitcasted from an all one value int.
1225 ///
1226 /// \param Semantics - type float semantics
1228
1229 /// Returns true if the given semantics has actual significand.
1230 ///
1231 /// \param Sem - type float semantics
1232 static bool hasSignificand(const fltSemantics &Sem) {
1233 return &Sem != &Float8E8M0FNU();
1234 }
1235
1236 /// Used to insert APFloat objects, or objects that contain APFloat objects,
1237 /// into FoldingSets.
1238 LLVM_ABI void Profile(FoldingSetNodeID &NID) const;
1239
1240 opStatus add(const APFloat &RHS, roundingMode RM) {
1241 assert(&getSemantics() == &RHS.getSemantics() &&
1242 "Should only call on two APFloats with the same semantics");
1243 if (usesLayout<IEEEFloat>(getSemantics()))
1244 return U.IEEE.add(RHS.U.IEEE, RM);
1245 if (usesLayout<DoubleAPFloat>(getSemantics()))
1246 return U.Double.add(RHS.U.Double, RM);
1247 llvm_unreachable("Unexpected semantics");
1248 }
1249 opStatus subtract(const APFloat &RHS, roundingMode RM) {
1250 assert(&getSemantics() == &RHS.getSemantics() &&
1251 "Should only call on two APFloats with the same semantics");
1252 if (usesLayout<IEEEFloat>(getSemantics()))
1253 return U.IEEE.subtract(RHS.U.IEEE, RM);
1254 if (usesLayout<DoubleAPFloat>(getSemantics()))
1255 return U.Double.subtract(RHS.U.Double, RM);
1256 llvm_unreachable("Unexpected semantics");
1257 }
1258 opStatus multiply(const APFloat &RHS, roundingMode RM) {
1259 assert(&getSemantics() == &RHS.getSemantics() &&
1260 "Should only call on two APFloats with the same semantics");
1261 if (usesLayout<IEEEFloat>(getSemantics()))
1262 return U.IEEE.multiply(RHS.U.IEEE, RM);
1263 if (usesLayout<DoubleAPFloat>(getSemantics()))
1264 return U.Double.multiply(RHS.U.Double, RM);
1265 llvm_unreachable("Unexpected semantics");
1266 }
1267 opStatus divide(const APFloat &RHS, roundingMode RM) {
1268 assert(&getSemantics() == &RHS.getSemantics() &&
1269 "Should only call on two APFloats with the same semantics");
1270 if (usesLayout<IEEEFloat>(getSemantics()))
1271 return U.IEEE.divide(RHS.U.IEEE, RM);
1272 if (usesLayout<DoubleAPFloat>(getSemantics()))
1273 return U.Double.divide(RHS.U.Double, RM);
1274 llvm_unreachable("Unexpected semantics");
1275 }
1276 opStatus remainder(const APFloat &RHS) {
1277 assert(&getSemantics() == &RHS.getSemantics() &&
1278 "Should only call on two APFloats with the same semantics");
1279 if (usesLayout<IEEEFloat>(getSemantics()))
1280 return U.IEEE.remainder(RHS.U.IEEE);
1281 if (usesLayout<DoubleAPFloat>(getSemantics()))
1282 return U.Double.remainder(RHS.U.Double);
1283 llvm_unreachable("Unexpected semantics");
1284 }
1285 opStatus mod(const APFloat &RHS) {
1286 assert(&getSemantics() == &RHS.getSemantics() &&
1287 "Should only call on two APFloats with the same semantics");
1288 if (usesLayout<IEEEFloat>(getSemantics()))
1289 return U.IEEE.mod(RHS.U.IEEE);
1290 if (usesLayout<DoubleAPFloat>(getSemantics()))
1291 return U.Double.mod(RHS.U.Double);
1292 llvm_unreachable("Unexpected semantics");
1293 }
1294 opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend,
1295 roundingMode RM) {
1296 assert(&getSemantics() == &Multiplicand.getSemantics() &&
1297 "Should only call on APFloats with the same semantics");
1298 assert(&getSemantics() == &Addend.getSemantics() &&
1299 "Should only call on APFloats with the same semantics");
1300 if (usesLayout<IEEEFloat>(getSemantics()))
1301 return U.IEEE.fusedMultiplyAdd(Multiplicand.U.IEEE, Addend.U.IEEE, RM);
1302 if (usesLayout<DoubleAPFloat>(getSemantics()))
1303 return U.Double.fusedMultiplyAdd(Multiplicand.U.Double, Addend.U.Double,
1304 RM);
1305 llvm_unreachable("Unexpected semantics");
1306 }
1310
1311 // TODO: bool parameters are not readable and a source of bugs.
1312 // Do something.
1313 opStatus next(bool nextDown) {
1315 }
1316
1317 /// Negate an APFloat.
1318 APFloat operator-() const {
1319 APFloat Result(*this);
1320 Result.changeSign();
1321 return Result;
1322 }
1323
1324 /// Add two APFloats, rounding ties to the nearest even.
1325 /// No error checking.
1326 APFloat operator+(const APFloat &RHS) const {
1327 APFloat Result(*this);
1328 (void)Result.add(RHS, rmNearestTiesToEven);
1329 return Result;
1330 }
1331
1332 /// Subtract two APFloats, rounding ties to the nearest even.
1333 /// No error checking.
1334 APFloat operator-(const APFloat &RHS) const {
1335 APFloat Result(*this);
1336 (void)Result.subtract(RHS, rmNearestTiesToEven);
1337 return Result;
1338 }
1339
1340 /// Multiply two APFloats, rounding ties to the nearest even.
1341 /// No error checking.
1342 APFloat operator*(const APFloat &RHS) const {
1343 APFloat Result(*this);
1344 (void)Result.multiply(RHS, rmNearestTiesToEven);
1345 return Result;
1346 }
1347
1348 /// Divide the first APFloat by the second, rounding ties to the nearest even.
1349 /// No error checking.
1350 APFloat operator/(const APFloat &RHS) const {
1351 APFloat Result(*this);
1352 (void)Result.divide(RHS, rmNearestTiesToEven);
1353 return Result;
1354 }
1355
1357 void clearSign() {
1358 if (isNegative())
1359 changeSign();
1360 }
1361 void copySign(const APFloat &RHS) {
1362 if (isNegative() != RHS.isNegative())
1363 changeSign();
1364 }
1365
1366 /// A static helper to produce a copy of an APFloat value with its sign
1367 /// copied from some other APFloat.
1368 static APFloat copySign(APFloat Value, const APFloat &Sign) {
1369 Value.copySign(Sign);
1370 return Value;
1371 }
1372
1373 /// Assuming this is an IEEE-754 NaN value, quiet its signaling bit.
1374 /// This preserves the sign and payload bits.
1375 [[nodiscard]] APFloat makeQuiet() const {
1376 APFloat Result(*this);
1377 Result.getIEEE().makeQuiet();
1378 return Result;
1379 }
1380
1381 LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM,
1382 bool *losesInfo);
1383 // Convert a floating point number to an integer according to the
1384 // rounding mode. We provide deterministic values in case of an invalid
1385 // operation exception, namely zero for NaNs and the minimal or maximal value
1386 // respectively for underflow or overflow.
1387 // The *IsExact output tells whether the result is exact, in the sense that
1388 // converting it back to the original floating point type produces the
1389 // original value. This is almost equivalent to result==opOK, except for
1390 // negative zeroes.
1392 unsigned int Width, bool IsSigned, roundingMode RM,
1393 bool *IsExact) const {
1395 convertToInteger(Input, Width, IsSigned, RM, IsExact));
1396 }
1397 // Same as convertToInteger(integerPart*, ...), except the result is returned
1398 // in an APSInt, whose initial bit-width and signed-ness are used to determine
1399 // the precision of the conversion.
1401 bool *IsExact) const;
1402
1403 // Convert a two's complement integer Input to a floating point number,
1404 // rounding according to RM. IsSigned is true if the integer is signed,
1405 // in which case it must be sign-extended.
1406 opStatus convertFromAPInt(const APInt &Input, bool IsSigned,
1407 roundingMode RM) {
1409 }
1410
1411 /// Fill this APFloat with the result of a string conversion.
1412 ///
1413 /// The following strings are accepted for conversion purposes:
1414 /// * Decimal floating-point literals (e.g., `0.1e-5`)
1415 /// * Hexadecimal floating-point literals (e.g., `0x1.0p-5`)
1416 /// * Positive infinity via "inf", "INFINITY", "Inf", "+Inf", or "+inf".
1417 /// * Negative infinity via "-inf", "-INFINITY", or "-Inf".
1418 /// * Quiet NaNs via "nan", "NaN", "nan(...)", or "NaN(...)", where the
1419 /// "..." is either a decimal or hexadecimal integer representing the
1420 /// payload. A negative sign may be optionally provided.
1421 /// * Signaling NaNs via "snan", "sNaN", "snan(...)", or "sNaN(...)", where
1422 /// the "..." is either a decimal or hexadecimal integer representing the
1423 /// payload. A negative sign may be optionally provided.
1424 ///
1425 /// If the input string is none of these forms, then an error is returned.
1426 ///
1427 /// If a floating-point exception occurs during conversion, then no error is
1428 /// returned, and the exception is indicated via opStatus.
1433
1434 /// Converts this APFloat to host double value.
1435 ///
1436 /// \pre The APFloat must be built using semantics, that can be represented by
1437 /// the host double type without loss of precision. It can be IEEEdouble and
1438 /// shorter semantics, like IEEEsingle and others.
1439 LLVM_ABI double convertToDouble() const;
1440
1441 /// Converts this APFloat to host float value.
1442 ///
1443 /// \pre The APFloat must be built using semantics, that can be represented by
1444 /// the host float type without loss of precision. It can be IEEEquad and
1445 /// shorter semantics, like IEEEdouble and others.
1446#ifdef HAS_IEE754_FLOAT128
1447 LLVM_ABI float128 convertToQuad() const;
1448#endif
1449
1450 /// Converts this APFloat to host float value.
1451 ///
1452 /// \pre The APFloat must be built using semantics, that can be represented by
1453 /// the host float type without loss of precision. It can be IEEEsingle and
1454 /// shorter semantics, like IEEEhalf.
1455 LLVM_ABI float convertToFloat() const;
1456
1457 bool operator==(const APFloat &RHS) const { return compare(RHS) == cmpEqual; }
1458
1459 bool operator!=(const APFloat &RHS) const { return compare(RHS) != cmpEqual; }
1460
1461 bool operator<(const APFloat &RHS) const {
1462 return compare(RHS) == cmpLessThan;
1463 }
1464
1465 bool operator>(const APFloat &RHS) const {
1466 return compare(RHS) == cmpGreaterThan;
1467 }
1468
1469 bool operator<=(const APFloat &RHS) const {
1470 cmpResult Res = compare(RHS);
1471 return Res == cmpLessThan || Res == cmpEqual;
1472 }
1473
1474 bool operator>=(const APFloat &RHS) const {
1475 cmpResult Res = compare(RHS);
1476 return Res == cmpGreaterThan || Res == cmpEqual;
1477 }
1478
1479 // IEEE comparison with another floating point number (NaNs compare unordered,
1480 // 0==-0).
1481 cmpResult compare(const APFloat &RHS) const {
1482 assert(&getSemantics() == &RHS.getSemantics() &&
1483 "Should only compare APFloats with the same semantics");
1484 if (usesLayout<IEEEFloat>(getSemantics()))
1485 return U.IEEE.compare(RHS.U.IEEE);
1486 if (usesLayout<DoubleAPFloat>(getSemantics()))
1487 return U.Double.compare(RHS.U.Double);
1488 llvm_unreachable("Unexpected semantics");
1489 }
1490
1491 // Compares the absolute value of this APFloat with another. Both operands
1492 // must be finite non-zero.
1493 cmpResult compareAbsoluteValue(const APFloat &RHS) const {
1494 assert(&getSemantics() == &RHS.getSemantics() &&
1495 "Should only compare APFloats with the same semantics");
1496 if (usesLayout<IEEEFloat>(getSemantics()))
1497 return U.IEEE.compareAbsoluteValue(RHS.U.IEEE);
1498 if (usesLayout<DoubleAPFloat>(getSemantics()))
1499 return U.Double.compareAbsoluteValue(RHS.U.Double);
1500 llvm_unreachable("Unexpected semantics");
1501 }
1502
1503 bool bitwiseIsEqual(const APFloat &RHS) const {
1504 if (&getSemantics() != &RHS.getSemantics())
1505 return false;
1506 if (usesLayout<IEEEFloat>(getSemantics()))
1507 return U.IEEE.bitwiseIsEqual(RHS.U.IEEE);
1508 if (usesLayout<DoubleAPFloat>(getSemantics()))
1509 return U.Double.bitwiseIsEqual(RHS.U.Double);
1510 llvm_unreachable("Unexpected semantics");
1511 }
1512
1513 /// We don't rely on operator== working on double values, as
1514 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1515 /// As such, this method can be used to do an exact bit-for-bit comparison of
1516 /// two floating point values.
1517 ///
1518 /// We leave the version with the double argument here because it's just so
1519 /// convenient to write "2.0" and the like. Without this function we'd
1520 /// have to duplicate its logic everywhere it's called.
1521 bool isExactlyValue(double V) const {
1522 bool ignored;
1523 APFloat Tmp(V);
1525 return bitwiseIsEqual(Tmp);
1526 }
1527
1528 unsigned int convertToHexString(char *DST, unsigned int HexDigits,
1529 bool UpperCase, roundingMode RM) const {
1531 convertToHexString(DST, HexDigits, UpperCase, RM));
1532 }
1533
1534 bool isZero() const { return getCategory() == fcZero; }
1535 bool isInfinity() const { return getCategory() == fcInfinity; }
1536 bool isNaN() const { return getCategory() == fcNaN; }
1537
1538 bool isNegative() const { return getIEEE().isNegative(); }
1540 bool isSignaling() const { return getIEEE().isSignaling(); }
1541
1542 bool isNormal() const { return !isDenormal() && isFiniteNonZero(); }
1543 bool isFinite() const { return !isNaN() && !isInfinity(); }
1544
1545 fltCategory getCategory() const { return getIEEE().getCategory(); }
1546 const fltSemantics &getSemantics() const { return *U.semantics; }
1547 bool isNonZero() const { return !isZero(); }
1548 bool isFiniteNonZero() const { return isFinite() && !isZero(); }
1549 bool isPosZero() const { return isZero() && !isNegative(); }
1550 bool isNegZero() const { return isZero() && isNegative(); }
1551 bool isPosInfinity() const { return isInfinity() && !isNegative(); }
1552 bool isNegInfinity() const { return isInfinity() && isNegative(); }
1556
1560
1561 /// If the value is a NaN value, return an integer containing the payload of
1562 /// this value. This payload will include the quiet bit as part of the
1563 /// returned integer.
1565 assert(isNaN() && "Can only call this on a NaN value");
1567 }
1568
1569 /// Return the FPClassTest which will return true for the value.
1571
1572 APFloat &operator=(const APFloat &RHS) = default;
1573 APFloat &operator=(APFloat &&RHS) = default;
1574
1575 void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision = 0,
1576 unsigned FormatMaxPadding = 3, bool TruncateZero = true) const {
1578 toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero));
1579 }
1580
1581 LLVM_ABI void print(raw_ostream &) const;
1582
1583#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1584 LLVM_DUMP_METHOD void dump() const;
1585#endif
1586
1587 /// If this value is normal and has an exact, normal, multiplicative inverse,
1588 /// store it in inv and return true.
1589 LLVM_ABI bool getExactInverse(APFloat *Inv) const;
1590
1591 // If this is an exact power of two, return the exponent while ignoring the
1592 // sign bit. If it's not an exact power of 2, return INT_MIN
1597
1598 // If this is an exact power of two, return the exponent. If it's not an exact
1599 // power of 2, return INT_MIN
1601 int getExactLog2() const {
1602 return isNegative() ? INT_MIN : getExactLog2Abs();
1603 }
1604
1605 LLVM_ABI friend hash_code hash_value(const APFloat &Arg);
1606 friend int ilogb(const APFloat &Arg);
1607 friend APFloat scalbn(APFloat X, int Exp, roundingMode RM);
1608 friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM);
1609 friend IEEEFloat;
1610 friend DoubleAPFloat;
1611};
1612
1613static_assert(sizeof(APFloat) == sizeof(detail::IEEEFloat),
1614 "Empty base class optimization is not performed.");
1615
1616/// See friend declarations above.
1617///
1618/// These additional declarations are required in order to compile LLVM with IBM
1619/// xlC compiler.
1621
1622/// Returns the exponent of the internal representation of the APFloat.
1623///
1624/// Because the radix of APFloat is 2, this is equivalent to floor(log2(x)).
1625/// For special APFloat values, this returns special error codes:
1626///
1627/// NaN -> \c IEK_NaN
1628/// 0 -> \c IEK_Zero
1629/// Inf -> \c IEK_Inf
1630///
1631inline int ilogb(const APFloat &Arg) {
1632 if (APFloat::usesLayout<detail::IEEEFloat>(Arg.getSemantics()))
1633 return ilogb(Arg.U.IEEE);
1634 if (APFloat::usesLayout<detail::DoubleAPFloat>(Arg.getSemantics()))
1635 return ilogb(Arg.U.Double);
1636 llvm_unreachable("Unexpected semantics");
1637}
1638
1639/// Returns: X * 2^Exp for integral exponents.
1641 if (APFloat::usesLayout<detail::IEEEFloat>(X.getSemantics()))
1642 return APFloat(scalbn(X.U.IEEE, Exp, RM), X.getSemantics());
1643 if (APFloat::usesLayout<detail::DoubleAPFloat>(X.getSemantics()))
1644 return APFloat(scalbn(X.U.Double, Exp, RM), X.getSemantics());
1645 llvm_unreachable("Unexpected semantics");
1646}
1647
1648/// Equivalent of C standard library function.
1649///
1650/// While the C standard says Exp is an unspecified value for infinity and nan,
1651/// this returns INT_MAX for infinities, and INT_MIN for NaNs.
1652inline APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM) {
1653 if (APFloat::usesLayout<detail::IEEEFloat>(X.getSemantics()))
1654 return APFloat(frexp(X.U.IEEE, Exp, RM), X.getSemantics());
1655 if (APFloat::usesLayout<detail::DoubleAPFloat>(X.getSemantics()))
1656 return APFloat(frexp(X.U.Double, Exp, RM), X.getSemantics());
1657 llvm_unreachable("Unexpected semantics");
1658}
1659/// Returns the absolute value of the argument.
1661 X.clearSign();
1662 return X;
1663}
1664
1665/// Returns the negated value of the argument.
1667 X.changeSign();
1668 return X;
1669}
1670
1671/// Implements IEEE-754 2008 minNum semantics. Returns the smaller of the
1672/// 2 arguments if both are not NaN. If either argument is a qNaN, returns the
1673/// other argument. If either argument is sNaN, return a qNaN.
1674/// -0 is treated as ordered less than +0.
1676inline APFloat minnum(const APFloat &A, const APFloat &B) {
1677 if (A.isSignaling())
1678 return A.makeQuiet();
1679 if (B.isSignaling())
1680 return B.makeQuiet();
1681 if (A.isNaN())
1682 return B;
1683 if (B.isNaN())
1684 return A;
1685 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1686 return A.isNegative() ? A : B;
1687 return B < A ? B : A;
1688}
1689
1690/// Implements IEEE-754 2008 maxNum semantics. Returns the larger of the
1691/// 2 arguments if both are not NaN. If either argument is a qNaN, returns the
1692/// other argument. If either argument is sNaN, return a qNaN.
1693/// +0 is treated as ordered greater than -0.
1695inline APFloat maxnum(const APFloat &A, const APFloat &B) {
1696 if (A.isSignaling())
1697 return A.makeQuiet();
1698 if (B.isSignaling())
1699 return B.makeQuiet();
1700 if (A.isNaN())
1701 return B;
1702 if (B.isNaN())
1703 return A;
1704 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1705 return A.isNegative() ? B : A;
1706 return A < B ? B : A;
1707}
1708
1709/// Implements IEEE 754-2019 minimum semantics. Returns the smaller of 2
1710/// arguments, returning a quiet NaN if an argument is a NaN and treating -0
1711/// as less than +0.
1713inline APFloat minimum(const APFloat &A, const APFloat &B) {
1714 if (A.isNaN())
1715 return A.makeQuiet();
1716 if (B.isNaN())
1717 return B.makeQuiet();
1718 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1719 return A.isNegative() ? A : B;
1720 return B < A ? B : A;
1721}
1722
1723/// Implements IEEE 754-2019 minimumNumber semantics. Returns the smaller
1724/// of 2 arguments, not propagating NaNs and treating -0 as less than +0.
1726inline APFloat minimumnum(const APFloat &A, const APFloat &B) {
1727 if (A.isNaN())
1728 return B.isNaN() ? B.makeQuiet() : B;
1729 if (B.isNaN())
1730 return A;
1731 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1732 return A.isNegative() ? A : B;
1733 return B < A ? B : A;
1734}
1735
1736/// Implements IEEE 754-2019 maximum semantics. Returns the larger of 2
1737/// arguments, returning a quiet NaN if an argument is a NaN and treating -0
1738/// as less than +0.
1740inline APFloat maximum(const APFloat &A, const APFloat &B) {
1741 if (A.isNaN())
1742 return A.makeQuiet();
1743 if (B.isNaN())
1744 return B.makeQuiet();
1745 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1746 return A.isNegative() ? B : A;
1747 return A < B ? B : A;
1748}
1749
1750/// Implements IEEE 754-2019 maximumNumber semantics. Returns the larger
1751/// of 2 arguments, not propagating NaNs and treating -0 as less than +0.
1753inline APFloat maximumnum(const APFloat &A, const APFloat &B) {
1754 if (A.isNaN())
1755 return B.isNaN() ? B.makeQuiet() : B;
1756 if (B.isNaN())
1757 return A;
1758 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1759 return A.isNegative() ? B : A;
1760 return A < B ? B : A;
1761}
1762
1764 V.print(OS);
1765 return OS;
1766}
1767
1768// We want the following functions to be available in the header for inlining.
1769// We cannot define them inline in the class definition of `DoubleAPFloat`
1770// because doing so would instantiate `std::unique_ptr<APFloat[]>` before
1771// `APFloat` is defined, and that would be undefined behavior.
1772namespace detail {
1773
1775 if (this != &RHS) {
1776 this->~DoubleAPFloat();
1777 new (this) DoubleAPFloat(std::move(RHS));
1778 }
1779 return *this;
1780}
1781
1782APFloat &DoubleAPFloat::getFirst() { return Floats[0]; }
1783const APFloat &DoubleAPFloat::getFirst() const { return Floats[0]; }
1784APFloat &DoubleAPFloat::getSecond() { return Floats[1]; }
1785const APFloat &DoubleAPFloat::getSecond() const { return Floats[1]; }
1786
1787inline DoubleAPFloat::~DoubleAPFloat() { delete[] Floats; }
1788
1789} // namespace detail
1790
1791} // namespace llvm
1792
1793#undef APFLOAT_DISPATCH_ON_SEMANTICS
1794#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...
#define X(NUM, ENUM, NAME)
Definition ELF.h:851
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 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:5999
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:6007
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:1179
static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for SNaN values.
Definition APFloat.h:1187
opStatus divide(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1267
APFloat & operator=(APFloat &&RHS)=default
bool isFiniteNonZero() const
Definition APFloat.h:1548
APFloat(const APFloat &RHS)=default
void copySign(const APFloat &RHS)
Definition APFloat.h:1361
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition APFloat.cpp:5899
LLVM_READONLY int getExactLog2Abs() const
Definition APFloat.h:1594
opStatus subtract(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1249
bool bitwiseIsEqual(const APFloat &RHS) const
Definition APFloat.h:1503
bool isNegative() const
Definition APFloat.h:1538
~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:5841
cmpResult compareAbsoluteValue(const APFloat &RHS) const
Definition APFloat.h:1493
APFloat operator+(const APFloat &RHS) const
Add two APFloats, rounding ties to the nearest even.
Definition APFloat.h:1326
friend DoubleAPFloat
Definition APFloat.h:1610
LLVM_ABI double convertToDouble() const
Converts this APFloat to host double value.
Definition APFloat.cpp:5958
bool isPosInfinity() const
Definition APFloat.h:1551
APFloat(APFloat &&RHS)=default
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
Definition APFloat.h:1575
bool isNormal() const
Definition APFloat.h:1542
bool isDenormal() const
Definition APFloat.h:1539
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:1521
opStatus add(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1240
LLVM_READONLY int getExactLog2() const
Definition APFloat.h:1601
APFloat(double d)
Definition APFloat.h:1126
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:5925
LLVM_ABI friend hash_code hash_value(const APFloat &Arg)
See friend declarations above.
Definition APFloat.cpp:5813
APFloat(const fltSemantics &Semantics, integerPart I)
Definition APFloat.h:1118
bool operator!=(const APFloat &RHS) const
Definition APFloat.h:1459
APFloat(const fltSemantics &Semantics, T V)=delete
const fltSemantics & getSemantics() const
Definition APFloat.h:1546
APFloat operator-(const APFloat &RHS) const
Subtract two APFloats, rounding ties to the nearest even.
Definition APFloat.h:1334
APFloat operator*(const APFloat &RHS) const
Multiply two APFloats, rounding ties to the nearest even.
Definition APFloat.h:1342
APFloat(const fltSemantics &Semantics)
Definition APFloat.h:1116
bool isNonZero() const
Definition APFloat.h:1547
void clearSign()
Definition APFloat.h:1357
bool operator<(const APFloat &RHS) const
Definition APFloat.h:1461
bool isFinite() const
Definition APFloat.h:1543
APFloat makeQuiet() const
Assuming this is an IEEE-754 NaN value, quiet its signaling bit.
Definition APFloat.h:1375
bool isNaN() const
Definition APFloat.h:1536
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
Definition APFloat.h:1406
static APFloat getOne(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative One.
Definition APFloat.h:1147
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
Definition APFloat.h:1528
opStatus multiply(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1258
LLVM_ABI float convertToFloat() const
Converts this APFloat to host float value.
Definition APFloat.cpp:5986
bool isSignaling() const
Definition APFloat.h:1540
bool operator>(const APFloat &RHS) const
Definition APFloat.h:1465
opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend, roundingMode RM)
Definition APFloat.h:1294
APFloat operator/(const APFloat &RHS) const
Divide the first APFloat by the second, rounding ties to the nearest even.
Definition APFloat.h:1350
opStatus remainder(const APFloat &RHS)
Definition APFloat.h:1276
APFloat operator-() const
Negate an APFloat.
Definition APFloat.h:1318
bool isZero() const
Definition APFloat.h:1534
static APFloat getSmallestNormalized(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
Definition APFloat.h:1217
APInt bitcastToAPInt() const
Definition APFloat.h:1430
bool isLargest() const
Definition APFloat.h:1554
friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM)
bool isSmallest() const
Definition APFloat.h:1553
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
Definition APFloat.h:1197
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
Definition APFloat.h:1391
opStatus next(bool nextDown)
Definition APFloat.h:1313
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
Definition APFloat.h:1157
friend APFloat scalbn(APFloat X, int Exp, roundingMode RM)
bool operator>=(const APFloat &RHS) const
Definition APFloat.h:1474
bool needsCleanup() const
Definition APFloat.h:1133
static APFloat getSmallest(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) finite number in the given semantics.
Definition APFloat.h:1207
LLVM_ABI FPClassTest classify() const
Return the FPClassTest which will return true for the value.
Definition APFloat.cpp:5828
bool operator==(const APFloat &RHS) const
Definition APFloat.h:1457
opStatus mod(const APFloat &RHS)
Definition APFloat.h:1285
bool isPosZero() const
Definition APFloat.h:1549
APInt getNaNPayload() const
If the value is a NaN value, return an integer containing the payload of this value.
Definition APFloat.h:1564
friend int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
Definition APFloat.h:1631
Expected< opStatus > convertFromString(StringRef, roundingMode)
Fill this APFloat with the result of a string conversion.
Definition APFloat.cpp:5808
fltCategory getCategory() const
Definition APFloat.h:1545
APFloat(const fltSemantics &Semantics, uninitializedTag)
Definition APFloat.h:1123
bool isInteger() const
Definition APFloat.h:1555
bool isNegInfinity() const
Definition APFloat.h:1552
friend IEEEFloat
Definition APFloat.h:1609
LLVM_DUMP_METHOD void dump() const
Definition APFloat.cpp:5936
bool isNegZero() const
Definition APFloat.h:1550
LLVM_ABI void print(raw_ostream &) const
Definition APFloat.cpp:5929
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:1368
APFloat(float f)
Definition APFloat.h:1127
opStatus roundToIntegral(roundingMode RM)
Definition APFloat.h:1307
void changeSign()
Definition APFloat.h:1356
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Definition APFloat.h:1168
static bool hasSignificand(const fltSemantics &Sem)
Returns true if the given semantics has actual significand.
Definition APFloat.h:1232
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Definition APFloat.h:1138
cmpResult compare(const APFloat &RHS) const
Definition APFloat.h:1481
bool isSmallestNormalized() const
Definition APFloat.h:1557
APFloat(const fltSemantics &Semantics, const APInt &I)
Definition APFloat.h:1125
bool isInfinity() const
Definition APFloat.h:1535
bool operator<=(const APFloat &RHS) const
Definition APFloat.h:1469
Class for arbitrary precision integers.
Definition APInt.h:78
uint64_t WordType
Definition APInt.h:80
static constexpr unsigned APINT_BITS_PER_WORD
Bits in a word.
Definition APInt.h:86
An arbitrary precision integer that knows its signedness.
Definition APSInt.h:24
Tagged union holding either a T or a Error.
Definition Error.h:485
This class is used to gather all the unique data bits of a node.
Definition FoldingSet.h:208
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI void makeSmallestNormalized(bool Neg)
Definition APFloat.cpp:5155
LLVM_ABI DoubleAPFloat & operator=(const DoubleAPFloat &RHS)
Definition APFloat.cpp:4685
LLVM_ABI void changeSign()
Definition APFloat.cpp:5062
LLVM_ABI bool isLargest() const
Definition APFloat.cpp:5629
LLVM_ABI opStatus remainder(const DoubleAPFloat &RHS)
Definition APFloat.cpp:4949
LLVM_ABI opStatus multiply(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4852
LLVM_ABI fltCategory getCategory() const
Definition APFloat.cpp:5121
LLVM_ABI bool bitwiseIsEqual(const DoubleAPFloat &RHS) const
Definition APFloat.cpp:5178
LLVM_ABI LLVM_READONLY int getExactLog2Abs() const
Definition APFloat.cpp:5653
LLVM_ABI opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
Definition APFloat.cpp:5580
LLVM_ABI APInt bitcastToAPInt() const
Definition APFloat.cpp:5189
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
Definition APFloat.cpp:5199
LLVM_ABI bool isSmallest() const
Definition APFloat.cpp:5612
LLVM_ABI opStatus subtract(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4844
LLVM_ABI friend hash_code hash_value(const DoubleAPFloat &Arg)
Definition APFloat.cpp:5183
LLVM_ABI cmpResult compareAbsoluteValue(const DoubleAPFloat &RHS) const
Definition APFloat.cpp:5068
LLVM_ABI bool isDenormal() const
Definition APFloat.cpp:5605
LLVM_ABI opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
Definition APFloat.cpp:5416
LLVM_ABI void makeSmallest(bool Neg)
Definition APFloat.cpp:5148
LLVM_ABI friend int ilogb(const DoubleAPFloat &X)
Definition APFloat.cpp:5662
LLVM_ABI opStatus next(bool nextDown)
Definition APFloat.cpp:5215
LLVM_ABI void makeInf(bool Neg)
Definition APFloat.cpp:5127
LLVM_ABI bool isInteger() const
Definition APFloat.cpp:5637
LLVM_ABI void makeZero(bool Neg)
Definition APFloat.cpp:5132
LLVM_ABI opStatus divide(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4938
LLVM_ABI bool isSmallestNormalized() const
Definition APFloat.cpp:5620
LLVM_ABI opStatus mod(const DoubleAPFloat &RHS)
Definition APFloat.cpp:4959
LLVM_ABI DoubleAPFloat(const fltSemantics &S)
Definition APFloat.cpp:4632
LLVM_ABI void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision, unsigned FormatMaxPadding, bool TruncateZero=true) const
Definition APFloat.cpp:5643
LLVM_ABI void makeLargest(bool Neg)
Definition APFloat.cpp:5137
LLVM_ABI cmpResult compare(const DoubleAPFloat &RHS) const
Definition APFloat.cpp:5170
LLVM_ABI friend DoubleAPFloat scalbn(const DoubleAPFloat &X, int Exp, roundingMode)
LLVM_ABI opStatus roundToIntegral(roundingMode RM)
Definition APFloat.cpp:4985
LLVM_ABI opStatus fusedMultiplyAdd(const DoubleAPFloat &Multiplicand, const DoubleAPFloat &Addend, roundingMode RM)
Definition APFloat.cpp:4970
LLVM_ABI unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
Definition APFloat.cpp:5595
bool needsCleanup() const
Definition APFloat.h:877
LLVM_ABI bool isNegative() const
Definition APFloat.cpp:5125
LLVM_ABI opStatus add(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4839
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:5165
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:3175
LLVM_ABI cmpResult compareAbsoluteValue(const IEEEFloat &) const
Definition APFloat.cpp:1424
LLVM_ABI opStatus mod(const IEEEFloat &)
C fmod, or llvm frem.
Definition APFloat.cpp:2180
fltCategory getCategory() const
Definition APFloat.h:582
LLVM_ABI opStatus convertFromAPInt(const APInt &, bool, roundingMode)
Definition APFloat.cpp:2735
APInt getNaNPayload() const
Definition APFloat.cpp:4520
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:3947
LLVM_ABI LLVM_READONLY int getExactLog2Abs() const
Definition APFloat.cpp:4342
LLVM_ABI APInt bitcastToAPInt() const
Definition APFloat.cpp:3573
LLVM_ABI friend IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
Definition APFloat.cpp:4592
LLVM_ABI cmpResult compare(const IEEEFloat &) const
IEEE comparison with another floating point number (NaNs compare unordered, 0==-0).
Definition APFloat.cpp:2348
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:2054
LLVM_ABI friend hash_code hash_value(const IEEEFloat &Arg)
Overload to compute a hash code for an APFloat value.
Definition APFloat.cpp:3315
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:2072
LLVM_ABI double convertToDouble() const
Definition APFloat.cpp:3643
LLVM_ABI float convertToFloat() const
Definition APFloat.cpp:3636
LLVM_ABI opStatus subtract(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2030
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:4298
LLVM_ABI void makeSmallest(bool Neg=false)
Make this number the smallest magnitude denormal number in the given semantics.
Definition APFloat.cpp:3979
LLVM_ABI void makeInf(bool Neg=false)
Definition APFloat.cpp:4539
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:945
friend class IEEEFloatUnitTestHelper
Definition APFloat.h:827
LLVM_ABI void makeQuiet()
Definition APFloat.cpp:4568
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:1047
LLVM_ABI opStatus add(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2024
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:3118
LLVM_ABI void makeNaN(bool SNaN=false, bool Neg=false, const APInt *fill=nullptr)
Definition APFloat.cpp:834
LLVM_ABI opStatus multiply(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2036
LLVM_ABI opStatus roundToIntegral(roundingMode)
Definition APFloat.cpp:2263
LLVM_ABI IEEEFloat & operator=(const IEEEFloat &)
Definition APFloat.cpp:906
LLVM_ABI bool bitwiseIsEqual(const IEEEFloat &) const
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
Definition APFloat.cpp:1072
LLVM_ABI void makeSmallestNormalized(bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
Definition APFloat.cpp:3993
LLVM_ABI bool isInteger() const
Returns true if and only if the number is an exact integer.
Definition APFloat.cpp:1064
bool isPosZero() const
Definition APFloat.h:586
LLVM_ABI IEEEFloat(const fltSemantics &)
Definition APFloat.cpp:1099
LLVM_ABI opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2217
LLVM_ABI friend int ilogb(const IEEEFloat &Arg)
Definition APFloat.cpp:4574
LLVM_ABI opStatus next(bool nextDown)
IEEE-754R 5.3.1: nextUp/nextDown.
Definition APFloat.cpp:4387
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:4371
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:4554
LLVM_ABI opStatus convert(const fltSemantics &, roundingMode, bool *)
IEEEFloat::convert - convert a value of one floating point type to another.
Definition APFloat.cpp:2424
LLVM_ABI void changeSign()
Definition APFloat.cpp:1982
LLVM_ABI bool isDenormal() const
IEEE-754R isSubnormal(): Returns true if and only if the float is a denormal.
Definition APFloat.cpp:931
LLVM_ABI opStatus convertToInteger(MutableArrayRef< integerPart >, unsigned int, bool, roundingMode, bool *) const
Definition APFloat.cpp:2680
LLVM_ABI friend IEEEFloat frexp(const IEEEFloat &X, int &Exp, roundingMode)
Definition APFloat.cpp:4613
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:937
bool isNegZero() const
Definition APFloat.h:587
An opaque object representing a hash code.
Definition Hashing.h:78
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:3315
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:4613
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:4574
static constexpr cmpResult cmpEqual
Definition APFloat.h:439
LLVM_ABI IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
Definition APFloat.cpp:4592
APFloatBase::integerPart integerPart
Definition APFloat.h:423
This is an optimization pass for GlobalISel generic memory operations.
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1758
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:1660
LLVM_READONLY APFloat maximum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 maximum semantics.
Definition APFloat.h:1740
int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
Definition APFloat.h:1631
APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM)
Equivalent of C standard library function.
Definition APFloat.h:1652
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE-754 2008 maxNum semantics.
Definition APFloat.h:1695
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:1726
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:1640
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:1676
fltNonfiniteBehavior
Definition APFloat.h:952
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:1666
LLVM_READONLY APFloat minimum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 minimum semantics.
Definition APFloat.h:1713
LLVM_READONLY APFloat maximumnum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 maximumNumber semantics.
Definition APFloat.h:1753
fltNanEncoding
Definition APFloat.h:976
APFloatBase::ExponentType maxExponent
Definition APFloat.h:1000
fltNonfiniteBehavior nonFiniteBehavior
Definition APFloat.h:1013
APFloatBase::ExponentType minExponent
Definition APFloat.h:1004
unsigned int sizeInBits
Definition APFloat.h:1011
unsigned int precision
Definition APFloat.h:1008
fltNanEncoding nanEncoding
Definition APFloat.h:1015