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