1c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===- llvm/ADT/APFloat.h - Arbitrary Precision Floating Point ---*- C++ -*-==//
2c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//
3c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//                     The LLVM Compiler Infrastructure
4c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//
5c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This file is distributed under the University of Illinois Open Source
6c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// License. See LICENSE.TXT for details.
7c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//
8c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===----------------------------------------------------------------------===//
9c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
10c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \file
11c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief
12c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// This file declares a class to represent arbitrary precision floating point
13c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// values and provide a variety of arithmetic operations on them.
14c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
15c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===----------------------------------------------------------------------===//
16c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
17c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#ifndef LLVM_ADT_APFLOAT_H
18c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#define LLVM_ADT_APFLOAT_H
19c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
20c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/APInt.h"
21c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/ArrayRef.h"
22c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/ErrorHandling.h"
23c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <memory>
24c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
25c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL)                             \
26c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  do {                                                                         \
27c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<IEEEFloat>(getSemantics()))                                 \
28c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.IEEE.METHOD_CALL;                                               \
29c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<DoubleAPFloat>(getSemantics()))                             \
30c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.Double.METHOD_CALL;                                             \
31c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Unexpected semantics");                                  \
32c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  } while (false)
33c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
34c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotnamespace llvm {
35c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
36c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotstruct fltSemantics;
37c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass APSInt;
38c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass StringRef;
39c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass APFloat;
40c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass raw_ostream;
41c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
42c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <typename T> class SmallVectorImpl;
43c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
44c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Enum that represents what fraction of the LSB truncated bits of an fp number
45c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// represent.
46c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
47c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// This essentially combines the roles of guard and sticky bits.
48c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotenum lostFraction { // Example of truncated bits:
49c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  lfExactlyZero,    // 000000
50c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  lfLessThanHalf,   // 0xxxxx  x's not all zero
51c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  lfExactlyHalf,    // 100000
52c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  lfMoreThanHalf    // 1xxxxx  x's not all zero
53c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot};
54c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
55c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// A self-contained host- and target-independent arbitrary-precision
56c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// floating-point software implementation.
57c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
58c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// APFloat uses bignum integer arithmetic as provided by static functions in
59c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// the APInt class.  The library will work with bignum integers whose parts are
60c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// any unsigned type at least 16 bits wide, but 64 bits is recommended.
61c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
62c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Written for clarity rather than speed, in particular with a view to use in
63c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// the front-end of a cross compiler so that target arithmetic can be correctly
64c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// performed on the host.  Performance should nonetheless be reasonable,
65c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// particularly for its intended use.  It may be useful as a base
66c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// implementation for a run-time library during development of a faster
67c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// target-specific one.
68c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
69c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// All 5 rounding modes in the IEEE-754R draft are handled correctly for all
70c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// implemented operations.  Currently implemented operations are add, subtract,
71c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// multiply, divide, fused-multiply-add, conversion-to-float,
72c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// conversion-to-integer and conversion-from-integer.  New rounding modes
73c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// (e.g. away from zero) can be added with three or four lines of code.
74c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
75c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Four formats are built-in: IEEE single precision, double precision,
76c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// quadruple precision, and x87 80-bit extended double (when operating with
77c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// full extended precision).  Adding a new format that obeys IEEE semantics
78c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// only requires adding two lines of code: a declaration and definition of the
79c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// format.
80c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
81c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// All operations return the status of that operation as an exception bit-mask,
82c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// so multiple operations can be done consecutively with their results or-ed
83c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// together.  The returned status can be useful for compiler diagnostics; e.g.,
84c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// inexact, underflow and overflow can be easily diagnosed on constant folding,
85c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// and compiler optimizers can determine what exceptions would be raised by
86c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// folding operations and optimize, or perhaps not optimize, accordingly.
87c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
88c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// At present, underflow tininess is detected after rounding; it should be
89c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// straight forward to add support for the before-rounding case too.
90c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
91c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// The library reads hexadecimal floating point numbers as per C99, and
92c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// correctly rounds if necessary according to the specified rounding mode.
93c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Syntax is required to have been validated by the caller.  It also converts
94c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// floating point numbers to hexadecimal text as per the C99 %a and %A
95c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// conversions.  The output precision (or alternatively the natural minimal
96c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// precision) can be specified; if the requested precision is less than the
97c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// natural precision the output is correctly rounded for the specified rounding
98c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// mode.
99c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
100c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// It also reads decimal floating point numbers and correctly rounds according
101c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// to the specified rounding mode.
102c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
103c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Conversion to decimal text is not currently implemented.
104c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
105c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Non-zero finite numbers are represented internally as a sign bit, a 16-bit
106c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// signed exponent, and the significand as an array of integer parts.  After
107c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// normalization of a number of precision P the exponent is within the range of
108c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// the format, and if the number is not denormal the P-th bit of the
109c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// significand is set as an explicit integer bit.  For denormals the most
110c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// significant bit is shifted right so that the exponent is maintained at the
111c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// format's minimum, so that the smallest denormal has just the least
112c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// significant bit of the significand set.  The sign of zeroes and infinities
113c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// is significant; the exponent and significand of such numbers is not stored,
114c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// but has a known implicit (deterministic) value: 0 for the significands, 0
115c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// for zero exponent, all 1 bits for infinity exponent.  For NaNs the sign and
116c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// significand are deterministic, although not really meaningful, and preserved
117c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// in non-conversion operations.  The exponent is implicitly all 1 bits.
118c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
119c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// APFloat does not provide any exception handling beyond default exception
120c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// handling. We represent Signaling NaNs via IEEE-754R 2008 6.2.1 should clause
121c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// by encoding Signaling NaNs with the first bit of its trailing significand as
122c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// 0.
123c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
124c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// TODO
125c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// ====
126c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
127c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Some features that may or may not be worth adding:
128c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
129c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Binary to decimal conversion (hard).
130c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
131c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Optional ability to detect underflow tininess before rounding.
132c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
133c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// New formats: x87 in single and double precision mode (IEEE apart from
134c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// extended exponent range) (hard).
135c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
136c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// New operations: sqrt, IEEE remainder, C90 fmod, nexttoward.
137c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
138c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
139c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This is the common type definitions shared by APFloat and its internal
140c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// implementation classes. This struct should not define any non-static data
141c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// members.
142c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotstruct APFloatBase {
143c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  typedef APInt::WordType integerPart;
144c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static const unsigned integerPartWidth = APInt::APINT_BITS_PER_WORD;
145c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
146c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// A signed type to represent a floating point numbers unbiased exponent.
147c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  typedef signed short ExponentType;
148c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
149c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \name Floating Point Semantics.
150c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @{
151c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
152c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static const fltSemantics &IEEEhalf() LLVM_READNONE;
153c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static const fltSemantics &IEEEsingle() LLVM_READNONE;
154c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static const fltSemantics &IEEEdouble() LLVM_READNONE;
155c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static const fltSemantics &IEEEquad() LLVM_READNONE;
156c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static const fltSemantics &PPCDoubleDouble() LLVM_READNONE;
157c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static const fltSemantics &x87DoubleExtended() LLVM_READNONE;
158c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
159c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// A Pseudo fltsemantic used to construct APFloats that cannot conflict with
160c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// anything real.
161c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static const fltSemantics &Bogus() LLVM_READNONE;
162c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
163c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @}
164c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
165c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// IEEE-754R 5.11: Floating Point Comparison Relations.
166c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  enum cmpResult {
167c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    cmpLessThan,
168c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    cmpEqual,
169c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    cmpGreaterThan,
170c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    cmpUnordered
171c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  };
172c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
173c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// IEEE-754R 4.3: Rounding-direction attributes.
174c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  enum roundingMode {
175c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    rmNearestTiesToEven,
176c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    rmTowardPositive,
177c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    rmTowardNegative,
178c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    rmTowardZero,
179c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    rmNearestTiesToAway
180c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  };
181c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
182c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// IEEE-754R 7: Default exception handling.
183c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
184c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// opUnderflow or opOverflow are always returned or-ed with opInexact.
185c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  enum opStatus {
186c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    opOK = 0x00,
187c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    opInvalidOp = 0x01,
188c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    opDivByZero = 0x02,
189c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    opOverflow = 0x04,
190c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    opUnderflow = 0x08,
191c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    opInexact = 0x10
192c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  };
193c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
194c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Category of internally-represented number.
195c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  enum fltCategory {
196c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    fcInfinity,
197c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    fcNaN,
198c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    fcNormal,
199c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    fcZero
200c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  };
201c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
202c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Convenience enum used to construct an uninitialized APFloat.
203c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  enum uninitializedTag {
204c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    uninitialized
205c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  };
206c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
207c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Enumeration of \c ilogb error results.
208c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  enum IlogbErrorKinds {
209c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    IEK_Zero = INT_MIN + 1,
210c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    IEK_NaN = INT_MIN,
211c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    IEK_Inf = INT_MAX
212c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  };
213c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
214c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static unsigned int semanticsPrecision(const fltSemantics &);
215c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static ExponentType semanticsMinExponent(const fltSemantics &);
216c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static ExponentType semanticsMaxExponent(const fltSemantics &);
217c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static unsigned int semanticsSizeInBits(const fltSemantics &);
218c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
219c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns the size of the floating point number (in bits) in the given
220c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// semantics.
221c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static unsigned getSizeInBits(const fltSemantics &Sem);
222c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot};
223c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
224c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotnamespace detail {
225c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
226c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass IEEEFloat final : public APFloatBase {
227c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic:
228c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \name Constructors
229c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @{
230c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
231c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  IEEEFloat(const fltSemantics &); // Default construct to 0.0
232c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  IEEEFloat(const fltSemantics &, integerPart);
233c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  IEEEFloat(const fltSemantics &, uninitializedTag);
234c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  IEEEFloat(const fltSemantics &, const APInt &);
235c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  explicit IEEEFloat(double d);
236c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  explicit IEEEFloat(float f);
237c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  IEEEFloat(const IEEEFloat &);
238c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  IEEEFloat(IEEEFloat &&);
239c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ~IEEEFloat();
240c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
241c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @}
242c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
243c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns whether this instance allocated memory.
244c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool needsCleanup() const { return partCount() > 1; }
245c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
246c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \name Convenience "constructors"
247c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @{
248c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
249c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @}
250c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
251c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \name Arithmetic
252c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @{
253c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
254c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus add(const IEEEFloat &, roundingMode);
255c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus subtract(const IEEEFloat &, roundingMode);
256c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus multiply(const IEEEFloat &, roundingMode);
257c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus divide(const IEEEFloat &, roundingMode);
258c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// IEEE remainder.
259c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus remainder(const IEEEFloat &);
260c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// C fmod, or llvm frem.
261c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus mod(const IEEEFloat &);
262c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &, roundingMode);
263c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus roundToIntegral(roundingMode);
264c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// IEEE-754R 5.3.1: nextUp/nextDown.
265c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus next(bool nextDown);
266c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
267c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @}
268c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
269c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \name Sign operations.
270c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @{
271c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
272c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void changeSign();
273c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
274c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @}
275c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
276c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \name Conversions
277c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @{
278c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
279c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convert(const fltSemantics &, roundingMode, bool *);
280c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertToInteger(MutableArrayRef<integerPart>, unsigned int, bool,
281c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                            roundingMode, bool *) const;
282c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertFromAPInt(const APInt &, bool, roundingMode);
283c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertFromSignExtendedInteger(const integerPart *, unsigned int,
284c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          bool, roundingMode);
285c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertFromZeroExtendedInteger(const integerPart *, unsigned int,
286c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          bool, roundingMode);
287c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertFromString(StringRef, roundingMode);
288c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APInt bitcastToAPInt() const;
289c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  double convertToDouble() const;
290c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  float convertToFloat() const;
291c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
292c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @}
293c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
294c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The definition of equality is not straightforward for floating point, so
295c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// we won't use operator==.  Use one of the following, or write whatever it
296c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// is you really mean.
297c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool operator==(const IEEEFloat &) const = delete;
298c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
299c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// IEEE comparison with another floating point number (NaNs compare
300c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// unordered, 0==-0).
301c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  cmpResult compare(const IEEEFloat &) const;
302c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
303c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
304c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool bitwiseIsEqual(const IEEEFloat &) const;
305c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
306c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Write out a hexadecimal representation of the floating point value to DST,
307c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// which must be of sufficient size, in the C99 form [-]0xh.hhhhp[+-]d.
308c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return the number of characters written, excluding the terminating NUL.
309c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned int convertToHexString(char *dst, unsigned int hexDigits,
310c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                  bool upperCase, roundingMode) const;
311c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
312c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \name IEEE-754R 5.7.2 General operations.
313c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @{
314c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
315c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// IEEE-754R isSignMinus: Returns true if and only if the current value is
316c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// negative.
317c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
318c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This applies to zeros and NaNs as well.
319c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isNegative() const { return sign; }
320c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
321c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// IEEE-754R isNormal: Returns true if and only if the current value is normal.
322c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
323c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This implies that the current value of the float is not zero, subnormal,
324c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// infinite, or NaN following the definition of normality from IEEE-754R.
325c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isNormal() const { return !isDenormal() && isFiniteNonZero(); }
326c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
327c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns true if and only if the current value is zero, subnormal, or
328c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// normal.
329c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
330c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This means that the value is not infinite or NaN.
331c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isFinite() const { return !isNaN() && !isInfinity(); }
332c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
333c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns true if and only if the float is plus or minus zero.
334c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isZero() const { return category == fcZero; }
335c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
336c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// IEEE-754R isSubnormal(): Returns true if and only if the float is a
337c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// denormal.
338c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isDenormal() const;
339c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
340c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
341c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isInfinity() const { return category == fcInfinity; }
342c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
343c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns true if and only if the float is a quiet or signaling NaN.
344c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isNaN() const { return category == fcNaN; }
345c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
346c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns true if and only if the float is a signaling NaN.
347c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isSignaling() const;
348c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
349c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @}
350c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
351c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \name Simple Queries
352c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @{
353c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
354c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  fltCategory getCategory() const { return category; }
355c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const fltSemantics &getSemantics() const { return *semantics; }
356c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isNonZero() const { return category != fcZero; }
357c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isFiniteNonZero() const { return isFinite() && !isZero(); }
358c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isPosZero() const { return isZero() && !isNegative(); }
359c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isNegZero() const { return isZero() && isNegative(); }
360c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
361c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns true if and only if the number has the smallest possible non-zero
362c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// magnitude in the current semantics.
363c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isSmallest() const;
364c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
365c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns true if and only if the number has the largest possible finite
366c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// magnitude in the current semantics.
367c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isLargest() const;
368c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
369c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns true if and only if the number is an exact integer.
370c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isInteger() const;
371c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
372c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @}
373c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
374c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  IEEEFloat &operator=(const IEEEFloat &);
375c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  IEEEFloat &operator=(IEEEFloat &&);
376c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
377c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Overload to compute a hash code for an APFloat value.
378c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
379c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Note that the use of hash codes for floating point values is in general
380c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// frought with peril. Equality is hard to define for these values. For
381c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// example, should negative and positive zero hash to different codes? Are
382c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// they equal or not? This hash value implementation specifically
383c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// emphasizes producing different codes for different inputs in order to
384c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// be used in canonicalization and memoization. As such, equality is
385c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// bitwiseIsEqual, and 0 != -0.
386c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend hash_code hash_value(const IEEEFloat &Arg);
387c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
388c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Converts this value into a decimal string.
389c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
390c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param FormatPrecision The maximum number of digits of
391c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   precision to output.  If there are fewer digits available,
392c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   zero padding will not be used unless the value is
393c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   integral and small enough to be expressed in
394c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   FormatPrecision digits.  0 means to use the natural
395c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   precision of the number.
396c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param FormatMaxPadding The maximum number of zeros to
397c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   consider inserting before falling back to scientific
398c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   notation.  0 means to always use scientific notation.
399c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
400c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param TruncateZero Indicate whether to remove the trailing zero in
401c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   fraction part or not. Also setting this parameter to false forcing
402c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   producing of output more similar to default printf behavior.
403c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   Specifically the lower e is used as exponent delimiter and exponent
404c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   always contains no less than two digits.
405c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
406c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Number       Precision    MaxPadding      Result
407c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// ------       ---------    ----------      ------
408c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 1.01E+4              5             2       10100
409c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 1.01E+4              4             2       1.01E+4
410c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 1.01E+4              5             1       1.01E+4
411c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 1.01E-2              5             2       0.0101
412c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 1.01E-2              4             2       0.0101
413c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 1.01E-2              4             1       1.01E-2
414c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision = 0,
415c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                unsigned FormatMaxPadding = 3, bool TruncateZero = true) const;
416c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
417c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If this value has an exact multiplicative inverse, store it in inv and
418c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// return true.
419c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool getExactInverse(APFloat *inv) const;
420c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
421c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns the exponent of the internal representation of the APFloat.
422c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
423c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Because the radix of APFloat is 2, this is equivalent to floor(log2(x)).
424c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For special APFloat values, this returns special error codes:
425c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
426c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   NaN -> \c IEK_NaN
427c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   0   -> \c IEK_Zero
428c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   Inf -> \c IEK_Inf
429c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
430c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend int ilogb(const IEEEFloat &Arg);
431c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
432c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns: X * 2^Exp for integral exponents.
433c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode);
434c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
435c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend IEEEFloat frexp(const IEEEFloat &X, int &Exp, roundingMode);
436c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
437c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \name Special value setters.
438c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @{
439c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
440c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeLargest(bool Neg = false);
441c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeSmallest(bool Neg = false);
442c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeNaN(bool SNaN = false, bool Neg = false,
443c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot               const APInt *fill = nullptr);
444c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeInf(bool Neg = false);
445c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeZero(bool Neg = false);
446c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeQuiet();
447c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
448c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns the smallest (by magnitude) normalized finite number in the given
449c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// semantics.
450c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
451c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param Negative - True iff the number should be negative
452c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeSmallestNormalized(bool Negative = false);
453c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
454c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @}
455c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
456c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  cmpResult compareAbsoluteValue(const IEEEFloat &) const;
457c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
458c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprivate:
459c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \name Simple Queries
460c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @{
461c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
462c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  integerPart *significandParts();
463c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const integerPart *significandParts() const;
464c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned int partCount() const;
465c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
466c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @}
467c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
468c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \name Significand operations.
469c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @{
470c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
471c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  integerPart addSignificand(const IEEEFloat &);
472c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  integerPart subtractSignificand(const IEEEFloat &, integerPart);
473c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  lostFraction addOrSubtractSignificand(const IEEEFloat &, bool subtract);
474c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  lostFraction multiplySignificand(const IEEEFloat &, const IEEEFloat *);
475c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  lostFraction divideSignificand(const IEEEFloat &);
476c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void incrementSignificand();
477c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void initialize(const fltSemantics *);
478c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void shiftSignificandLeft(unsigned int);
479c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  lostFraction shiftSignificandRight(unsigned int);
480c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned int significandLSB() const;
481c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned int significandMSB() const;
482c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void zeroSignificand();
483c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if the significand excluding the integral bit is all ones.
484c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isSignificandAllOnes() const;
485c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if the significand excluding the integral bit is all zeros.
486c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isSignificandAllZeros() const;
487c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
488c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @}
489c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
490c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \name Arithmetic on special values.
491c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @{
492c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
493c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus addOrSubtractSpecials(const IEEEFloat &, bool subtract);
494c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus divideSpecials(const IEEEFloat &);
495c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus multiplySpecials(const IEEEFloat &);
496c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus modSpecials(const IEEEFloat &);
497c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
498c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @}
499c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
500c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \name Miscellany
501c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @{
502c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
503c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool convertFromStringSpecials(StringRef str);
504c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus normalize(roundingMode, lostFraction);
505c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus addOrSubtract(const IEEEFloat &, roundingMode, bool subtract);
506c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus handleOverflow(roundingMode);
507c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool roundAwayFromZero(roundingMode, lostFraction, unsigned int) const;
508c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertToSignExtendedInteger(MutableArrayRef<integerPart>,
509c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                        unsigned int, bool, roundingMode,
510c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                        bool *) const;
511c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertFromUnsignedParts(const integerPart *, unsigned int,
512c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                    roundingMode);
513c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertFromHexadecimalString(StringRef, roundingMode);
514c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertFromDecimalString(StringRef, roundingMode);
515c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  char *convertNormalToHexString(char *, unsigned int, bool,
516c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                 roundingMode) const;
517c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus roundSignificandWithExponent(const integerPart *, unsigned int, int,
518c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                        roundingMode);
519c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
520c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @}
521c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
522c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APInt convertHalfAPFloatToAPInt() const;
523c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APInt convertFloatAPFloatToAPInt() const;
524c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APInt convertDoubleAPFloatToAPInt() const;
525c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APInt convertQuadrupleAPFloatToAPInt() const;
526c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APInt convertF80LongDoubleAPFloatToAPInt() const;
527c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APInt convertPPCDoubleDoubleAPFloatToAPInt() const;
528c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void initFromAPInt(const fltSemantics *Sem, const APInt &api);
529c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void initFromHalfAPInt(const APInt &api);
530c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void initFromFloatAPInt(const APInt &api);
531c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void initFromDoubleAPInt(const APInt &api);
532c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void initFromQuadrupleAPInt(const APInt &api);
533c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void initFromF80LongDoubleAPInt(const APInt &api);
534c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void initFromPPCDoubleDoubleAPInt(const APInt &api);
535c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
536c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void assign(const IEEEFloat &);
537c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void copySignificand(const IEEEFloat &);
538c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void freeSignificand();
539c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
540c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Note: this must be the first data member.
541c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The semantics that this value obeys.
542c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const fltSemantics *semantics;
543c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
544c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// A binary fraction with an explicit integer bit.
545c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
546c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The significand must be at least one bit wider than the target precision.
547c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  union Significand {
548c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    integerPart part;
549c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    integerPart *parts;
550c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  } significand;
551c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
552c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The signed unbiased exponent of the value.
553c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ExponentType exponent;
554c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
555c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// What kind of floating point number this is.
556c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
557c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Only 2 bits are required, but VisualStudio incorrectly sign extends it.
558c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Using the extra bit keeps it from failing under VisualStudio.
559c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  fltCategory category : 3;
560c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
561c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Sign bit of the number.
562c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned int sign : 1;
563c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot};
564c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
565c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robothash_code hash_value(const IEEEFloat &Arg);
566c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotint ilogb(const IEEEFloat &Arg);
567c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotIEEEFloat scalbn(IEEEFloat X, int Exp, IEEEFloat::roundingMode);
568c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotIEEEFloat frexp(const IEEEFloat &Val, int &Exp, IEEEFloat::roundingMode RM);
569c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
570c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This mode implements more precise float in terms of two APFloats.
571c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// The interface and layout is designed for arbitray underlying semantics,
572c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// though currently only PPCDoubleDouble semantics are supported, whose
573c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// corresponding underlying semantics are IEEEdouble.
574c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass DoubleAPFloat final : public APFloatBase {
575c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // Note: this must be the first data member.
576c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const fltSemantics *Semantics;
577c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  std::unique_ptr<APFloat[]> Floats;
578c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
579c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus addImpl(const APFloat &a, const APFloat &aa, const APFloat &c,
580c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                   const APFloat &cc, roundingMode RM);
581c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
582c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus addWithSpecial(const DoubleAPFloat &LHS, const DoubleAPFloat &RHS,
583c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                          DoubleAPFloat &Out, roundingMode RM);
584c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
585c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic:
586c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  DoubleAPFloat(const fltSemantics &S);
587c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  DoubleAPFloat(const fltSemantics &S, uninitializedTag);
588c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  DoubleAPFloat(const fltSemantics &S, integerPart);
589c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  DoubleAPFloat(const fltSemantics &S, const APInt &I);
590c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  DoubleAPFloat(const fltSemantics &S, APFloat &&First, APFloat &&Second);
591c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  DoubleAPFloat(const DoubleAPFloat &RHS);
592c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  DoubleAPFloat(DoubleAPFloat &&RHS);
593c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
594c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  DoubleAPFloat &operator=(const DoubleAPFloat &RHS);
595c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
596c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  DoubleAPFloat &operator=(DoubleAPFloat &&RHS) {
597c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (this != &RHS) {
598c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      this->~DoubleAPFloat();
599c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      new (this) DoubleAPFloat(std::move(RHS));
600c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    }
601c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return *this;
602c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
603c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
604c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool needsCleanup() const { return Floats != nullptr; }
605c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
606c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APFloat &getFirst() { return Floats[0]; }
607c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const APFloat &getFirst() const { return Floats[0]; }
608c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APFloat &getSecond() { return Floats[1]; }
609c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const APFloat &getSecond() const { return Floats[1]; }
610c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
611c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus add(const DoubleAPFloat &RHS, roundingMode RM);
612c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus subtract(const DoubleAPFloat &RHS, roundingMode RM);
613c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus multiply(const DoubleAPFloat &RHS, roundingMode RM);
614c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus divide(const DoubleAPFloat &RHS, roundingMode RM);
615c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus remainder(const DoubleAPFloat &RHS);
616c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus mod(const DoubleAPFloat &RHS);
617c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus fusedMultiplyAdd(const DoubleAPFloat &Multiplicand,
618c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                            const DoubleAPFloat &Addend, roundingMode RM);
619c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus roundToIntegral(roundingMode RM);
620c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void changeSign();
621c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  cmpResult compareAbsoluteValue(const DoubleAPFloat &RHS) const;
622c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
623c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  fltCategory getCategory() const;
624c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isNegative() const;
625c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
626c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeInf(bool Neg);
627c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeZero(bool Neg);
628c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeLargest(bool Neg);
629c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeSmallest(bool Neg);
630c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeSmallestNormalized(bool Neg);
631c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeNaN(bool SNaN, bool Neg, const APInt *fill);
632c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
633c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  cmpResult compare(const DoubleAPFloat &RHS) const;
634c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool bitwiseIsEqual(const DoubleAPFloat &RHS) const;
635c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APInt bitcastToAPInt() const;
636c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertFromString(StringRef, roundingMode);
637c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus next(bool nextDown);
638c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
639c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertToInteger(MutableArrayRef<integerPart> Input,
640c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                            unsigned int Width, bool IsSigned, roundingMode RM,
641c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                            bool *IsExact) const;
642c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM);
643c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertFromSignExtendedInteger(const integerPart *Input,
644c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          unsigned int InputSize, bool IsSigned,
645c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          roundingMode RM);
646c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertFromZeroExtendedInteger(const integerPart *Input,
647c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          unsigned int InputSize, bool IsSigned,
648c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          roundingMode RM);
649c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned int convertToHexString(char *DST, unsigned int HexDigits,
650c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                  bool UpperCase, roundingMode RM) const;
651c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
652c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isDenormal() const;
653c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isSmallest() const;
654c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isLargest() const;
655c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isInteger() const;
656c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
657c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision,
658c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                unsigned FormatMaxPadding, bool TruncateZero = true) const;
659c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
660c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool getExactInverse(APFloat *inv) const;
661c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
662c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend int ilogb(const DoubleAPFloat &Arg);
663c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend DoubleAPFloat scalbn(DoubleAPFloat X, int Exp, roundingMode);
664c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend DoubleAPFloat frexp(const DoubleAPFloat &X, int &Exp, roundingMode);
665c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend hash_code hash_value(const DoubleAPFloat &Arg);
666c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot};
667c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
668c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robothash_code hash_value(const DoubleAPFloat &Arg);
669c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
670c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} // End detail namespace
671c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
672c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This is a interface class that is currently forwarding functionalities from
673c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// detail::IEEEFloat.
674c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass APFloat : public APFloatBase {
675c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  typedef detail::IEEEFloat IEEEFloat;
676c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  typedef detail::DoubleAPFloat DoubleAPFloat;
677c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
678c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static_assert(std::is_standard_layout<IEEEFloat>::value, "");
679c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
680c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  union Storage {
681c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    const fltSemantics *semantics;
682c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    IEEEFloat IEEE;
683c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    DoubleAPFloat Double;
684c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
685c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    explicit Storage(IEEEFloat F, const fltSemantics &S);
686c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    explicit Storage(DoubleAPFloat F, const fltSemantics &S)
687c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        : Double(std::move(F)) {
688c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      assert(&S == &PPCDoubleDouble());
689c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    }
690c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
691c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    template <typename... ArgTypes>
692c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    Storage(const fltSemantics &Semantics, ArgTypes &&... Args) {
693c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      if (usesLayout<IEEEFloat>(Semantics)) {
694c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        new (&IEEE) IEEEFloat(Semantics, std::forward<ArgTypes>(Args)...);
695c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        return;
696c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      }
697c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      if (usesLayout<DoubleAPFloat>(Semantics)) {
698c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        new (&Double) DoubleAPFloat(Semantics, std::forward<ArgTypes>(Args)...);
699c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        return;
700c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      }
701c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      llvm_unreachable("Unexpected semantics");
702c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    }
703c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
704c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    ~Storage() {
705c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      if (usesLayout<IEEEFloat>(*semantics)) {
706c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        IEEE.~IEEEFloat();
707c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        return;
708c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      }
709c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      if (usesLayout<DoubleAPFloat>(*semantics)) {
710c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        Double.~DoubleAPFloat();
711c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        return;
712c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      }
713c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      llvm_unreachable("Unexpected semantics");
714c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    }
715c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
716c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    Storage(const Storage &RHS) {
717c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      if (usesLayout<IEEEFloat>(*RHS.semantics)) {
718c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        new (this) IEEEFloat(RHS.IEEE);
719c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        return;
720c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      }
721c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      if (usesLayout<DoubleAPFloat>(*RHS.semantics)) {
722c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        new (this) DoubleAPFloat(RHS.Double);
723c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        return;
724c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      }
725c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      llvm_unreachable("Unexpected semantics");
726c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    }
727c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
728c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    Storage(Storage &&RHS) {
729c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      if (usesLayout<IEEEFloat>(*RHS.semantics)) {
730c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        new (this) IEEEFloat(std::move(RHS.IEEE));
731c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        return;
732c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      }
733c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      if (usesLayout<DoubleAPFloat>(*RHS.semantics)) {
734c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        new (this) DoubleAPFloat(std::move(RHS.Double));
735c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        return;
736c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      }
737c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      llvm_unreachable("Unexpected semantics");
738c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    }
739c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
740c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    Storage &operator=(const Storage &RHS) {
741c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      if (usesLayout<IEEEFloat>(*semantics) &&
742c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot          usesLayout<IEEEFloat>(*RHS.semantics)) {
743c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        IEEE = RHS.IEEE;
744c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      } else if (usesLayout<DoubleAPFloat>(*semantics) &&
745c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                 usesLayout<DoubleAPFloat>(*RHS.semantics)) {
746c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        Double = RHS.Double;
747c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      } else if (this != &RHS) {
748c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        this->~Storage();
749c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        new (this) Storage(RHS);
750c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      }
751c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return *this;
752c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    }
753c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
754c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    Storage &operator=(Storage &&RHS) {
755c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      if (usesLayout<IEEEFloat>(*semantics) &&
756c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot          usesLayout<IEEEFloat>(*RHS.semantics)) {
757c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        IEEE = std::move(RHS.IEEE);
758c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      } else if (usesLayout<DoubleAPFloat>(*semantics) &&
759c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                 usesLayout<DoubleAPFloat>(*RHS.semantics)) {
760c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        Double = std::move(RHS.Double);
761c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      } else if (this != &RHS) {
762c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        this->~Storage();
763c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        new (this) Storage(std::move(RHS));
764c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      }
765c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return *this;
766c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    }
767c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  } U;
768c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
769c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  template <typename T> static bool usesLayout(const fltSemantics &Semantics) {
770c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    static_assert(std::is_same<T, IEEEFloat>::value ||
771c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                  std::is_same<T, DoubleAPFloat>::value, "");
772c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (std::is_same<T, DoubleAPFloat>::value) {
773c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return &Semantics == &PPCDoubleDouble();
774c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    }
775c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return &Semantics != &PPCDoubleDouble();
776c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
777c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
778c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  IEEEFloat &getIEEE() {
779c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<IEEEFloat>(*U.semantics))
780c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.IEEE;
781c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<DoubleAPFloat>(*U.semantics))
782c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.Double.getFirst().U.IEEE;
783c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Unexpected semantics");
784c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
785c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
786c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const IEEEFloat &getIEEE() const {
787c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<IEEEFloat>(*U.semantics))
788c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.IEEE;
789c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<DoubleAPFloat>(*U.semantics))
790c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.Double.getFirst().U.IEEE;
791c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Unexpected semantics");
792c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
793c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
794c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeZero(bool Neg) { APFLOAT_DISPATCH_ON_SEMANTICS(makeZero(Neg)); }
795c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
796c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeInf(bool Neg) { APFLOAT_DISPATCH_ON_SEMANTICS(makeInf(Neg)); }
797c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
798c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeNaN(bool SNaN, bool Neg, const APInt *fill) {
799c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFLOAT_DISPATCH_ON_SEMANTICS(makeNaN(SNaN, Neg, fill));
800c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
801c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
802c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeLargest(bool Neg) {
803c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFLOAT_DISPATCH_ON_SEMANTICS(makeLargest(Neg));
804c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
805c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
806c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeSmallest(bool Neg) {
807c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFLOAT_DISPATCH_ON_SEMANTICS(makeSmallest(Neg));
808c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
809c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
810c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void makeSmallestNormalized(bool Neg) {
811c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFLOAT_DISPATCH_ON_SEMANTICS(makeSmallestNormalized(Neg));
812c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
813c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
814c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // FIXME: This is due to clang 3.3 (or older version) always checks for the
815c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // default constructor in an array aggregate initialization, even if no
816c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // elements in the array is default initialized.
817c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APFloat() : U(IEEEdouble()) {
818c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("This is a workaround for old clang.");
819c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
820c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
821c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  explicit APFloat(IEEEFloat F, const fltSemantics &S) : U(std::move(F), S) {}
822c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  explicit APFloat(DoubleAPFloat F, const fltSemantics &S)
823c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      : U(std::move(F), S) {}
824c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
825c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  cmpResult compareAbsoluteValue(const APFloat &RHS) const {
826c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    assert(&getSemantics() == &RHS.getSemantics() &&
827c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot           "Should only compare APFloats with the same semantics");
828c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<IEEEFloat>(getSemantics()))
829c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.IEEE.compareAbsoluteValue(RHS.U.IEEE);
830c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<DoubleAPFloat>(getSemantics()))
831c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.Double.compareAbsoluteValue(RHS.U.Double);
832c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Unexpected semantics");
833c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
834c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
835c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic:
836c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APFloat(const fltSemantics &Semantics) : U(Semantics) {}
837c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APFloat(const fltSemantics &Semantics, StringRef S);
838c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APFloat(const fltSemantics &Semantics, integerPart I) : U(Semantics, I) {}
839c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // TODO: Remove this constructor. This isn't faster than the first one.
840c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APFloat(const fltSemantics &Semantics, uninitializedTag)
841c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      : U(Semantics, uninitialized) {}
842c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APFloat(const fltSemantics &Semantics, const APInt &I) : U(Semantics, I) {}
843c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  explicit APFloat(double d) : U(IEEEFloat(d), IEEEdouble()) {}
844c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  explicit APFloat(float f) : U(IEEEFloat(f), IEEEsingle()) {}
845c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APFloat(const APFloat &RHS) = default;
846c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APFloat(APFloat &&RHS) = default;
847c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
848c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ~APFloat() = default;
849c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
850c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool needsCleanup() const { APFLOAT_DISPATCH_ON_SEMANTICS(needsCleanup()); }
851c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
852c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Factory for Positive and Negative Zero.
853c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
854c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param Negative True iff the number should be negative.
855c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static APFloat getZero(const fltSemantics &Sem, bool Negative = false) {
856c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFloat Val(Sem, uninitialized);
857c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    Val.makeZero(Negative);
858c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return Val;
859c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
860c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
861c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Factory for Positive and Negative Infinity.
862c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
863c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param Negative True iff the number should be negative.
864c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static APFloat getInf(const fltSemantics &Sem, bool Negative = false) {
865c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFloat Val(Sem, uninitialized);
866c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    Val.makeInf(Negative);
867c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return Val;
868c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
869c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
870c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Factory for NaN values.
871c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
872c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param Negative - True iff the NaN generated should be negative.
873c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param type - The unspecified fill bits for creating the NaN, 0 by
874c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// default.  The value is truncated as necessary.
875c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static APFloat getNaN(const fltSemantics &Sem, bool Negative = false,
876c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                        unsigned type = 0) {
877c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (type) {
878c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      APInt fill(64, type);
879c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return getQNaN(Sem, Negative, &fill);
880c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    } else {
881c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return getQNaN(Sem, Negative, nullptr);
882c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    }
883c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
884c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
885c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Factory for QNaN values.
886c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static APFloat getQNaN(const fltSemantics &Sem, bool Negative = false,
887c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                         const APInt *payload = nullptr) {
888c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFloat Val(Sem, uninitialized);
889c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    Val.makeNaN(false, Negative, payload);
890c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return Val;
891c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
892c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
893c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Factory for SNaN values.
894c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static APFloat getSNaN(const fltSemantics &Sem, bool Negative = false,
895c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                         const APInt *payload = nullptr) {
896c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFloat Val(Sem, uninitialized);
897c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    Val.makeNaN(true, Negative, payload);
898c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return Val;
899c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
900c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
901c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns the largest finite number in the given semantics.
902c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
903c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param Negative - True iff the number should be negative
904c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static APFloat getLargest(const fltSemantics &Sem, bool Negative = false) {
905c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFloat Val(Sem, uninitialized);
906c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    Val.makeLargest(Negative);
907c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return Val;
908c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
909c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
910c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns the smallest (by magnitude) finite number in the given semantics.
911c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Might be denormalized, which implies a relative loss of precision.
912c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
913c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param Negative - True iff the number should be negative
914c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static APFloat getSmallest(const fltSemantics &Sem, bool Negative = false) {
915c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFloat Val(Sem, uninitialized);
916c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    Val.makeSmallest(Negative);
917c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return Val;
918c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
919c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
920c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns the smallest (by magnitude) normalized finite number in the given
921c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// semantics.
922c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
923c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param Negative - True iff the number should be negative
924c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static APFloat getSmallestNormalized(const fltSemantics &Sem,
925c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                       bool Negative = false) {
926c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFloat Val(Sem, uninitialized);
927c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    Val.makeSmallestNormalized(Negative);
928c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return Val;
929c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
930c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
931c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns a float which is bitcasted from an all one value int.
932c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
933c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param BitWidth - Select float type
934c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param isIEEE   - If 128 bit number, select between PPC and IEEE
935c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static APFloat getAllOnesValue(unsigned BitWidth, bool isIEEE = false);
936c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
937c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Used to insert APFloat objects, or objects that contain APFloat objects,
938c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// into FoldingSets.
939c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void Profile(FoldingSetNodeID &NID) const;
940c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
941c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus add(const APFloat &RHS, roundingMode RM) {
942c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    assert(&getSemantics() == &RHS.getSemantics() &&
943c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot           "Should only call on two APFloats with the same semantics");
944c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<IEEEFloat>(getSemantics()))
945c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.IEEE.add(RHS.U.IEEE, RM);
946c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<DoubleAPFloat>(getSemantics()))
947c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.Double.add(RHS.U.Double, RM);
948c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Unexpected semantics");
949c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
950c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus subtract(const APFloat &RHS, roundingMode RM) {
951c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    assert(&getSemantics() == &RHS.getSemantics() &&
952c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot           "Should only call on two APFloats with the same semantics");
953c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<IEEEFloat>(getSemantics()))
954c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.IEEE.subtract(RHS.U.IEEE, RM);
955c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<DoubleAPFloat>(getSemantics()))
956c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.Double.subtract(RHS.U.Double, RM);
957c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Unexpected semantics");
958c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
959c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus multiply(const APFloat &RHS, roundingMode RM) {
960c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    assert(&getSemantics() == &RHS.getSemantics() &&
961c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot           "Should only call on two APFloats with the same semantics");
962c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<IEEEFloat>(getSemantics()))
963c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.IEEE.multiply(RHS.U.IEEE, RM);
964c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<DoubleAPFloat>(getSemantics()))
965c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.Double.multiply(RHS.U.Double, RM);
966c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Unexpected semantics");
967c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
968c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus divide(const APFloat &RHS, roundingMode RM) {
969c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    assert(&getSemantics() == &RHS.getSemantics() &&
970c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot           "Should only call on two APFloats with the same semantics");
971c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<IEEEFloat>(getSemantics()))
972c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.IEEE.divide(RHS.U.IEEE, RM);
973c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<DoubleAPFloat>(getSemantics()))
974c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.Double.divide(RHS.U.Double, RM);
975c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Unexpected semantics");
976c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
977c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus remainder(const APFloat &RHS) {
978c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    assert(&getSemantics() == &RHS.getSemantics() &&
979c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot           "Should only call on two APFloats with the same semantics");
980c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<IEEEFloat>(getSemantics()))
981c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.IEEE.remainder(RHS.U.IEEE);
982c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<DoubleAPFloat>(getSemantics()))
983c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.Double.remainder(RHS.U.Double);
984c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Unexpected semantics");
985c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
986c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus mod(const APFloat &RHS) {
987c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    assert(&getSemantics() == &RHS.getSemantics() &&
988c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot           "Should only call on two APFloats with the same semantics");
989c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<IEEEFloat>(getSemantics()))
990c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.IEEE.mod(RHS.U.IEEE);
991c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<DoubleAPFloat>(getSemantics()))
992c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.Double.mod(RHS.U.Double);
993c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Unexpected semantics");
994c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
995c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend,
996c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                            roundingMode RM) {
997c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    assert(&getSemantics() == &Multiplicand.getSemantics() &&
998c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot           "Should only call on APFloats with the same semantics");
999c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    assert(&getSemantics() == &Addend.getSemantics() &&
1000c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot           "Should only call on APFloats with the same semantics");
1001c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<IEEEFloat>(getSemantics()))
1002c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.IEEE.fusedMultiplyAdd(Multiplicand.U.IEEE, Addend.U.IEEE, RM);
1003c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<DoubleAPFloat>(getSemantics()))
1004c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.Double.fusedMultiplyAdd(Multiplicand.U.Double, Addend.U.Double,
1005c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                       RM);
1006c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Unexpected semantics");
1007c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1008c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus roundToIntegral(roundingMode RM) {
1009c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFLOAT_DISPATCH_ON_SEMANTICS(roundToIntegral(RM));
1010c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1011c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1012c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // TODO: bool parameters are not readable and a source of bugs.
1013c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // Do something.
1014c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus next(bool nextDown) {
1015c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFLOAT_DISPATCH_ON_SEMANTICS(next(nextDown));
1016c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1017c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1018c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Add two APFloats, rounding ties to the nearest even.
1019c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// No error checking.
1020c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APFloat operator+(const APFloat &RHS) const {
1021c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFloat Result(*this);
1022c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    (void)Result.add(RHS, rmNearestTiesToEven);
1023c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return Result;
1024c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1025c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1026c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Subtract two APFloats, rounding ties to the nearest even.
1027c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// No error checking.
1028c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APFloat operator-(const APFloat &RHS) const {
1029c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFloat Result(*this);
1030c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    (void)Result.subtract(RHS, rmNearestTiesToEven);
1031c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return Result;
1032c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1033c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1034c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Multiply two APFloats, rounding ties to the nearest even.
1035c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// No error checking.
1036c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APFloat operator*(const APFloat &RHS) const {
1037c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFloat Result(*this);
1038c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    (void)Result.multiply(RHS, rmNearestTiesToEven);
1039c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return Result;
1040c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1041c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1042c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Divide the first APFloat by the second, rounding ties to the nearest even.
1043c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// No error checking.
1044c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APFloat operator/(const APFloat &RHS) const {
1045c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFloat Result(*this);
1046c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    (void)Result.divide(RHS, rmNearestTiesToEven);
1047c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return Result;
1048c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1049c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1050c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void changeSign() { APFLOAT_DISPATCH_ON_SEMANTICS(changeSign()); }
1051c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void clearSign() {
1052c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (isNegative())
1053c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      changeSign();
1054c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1055c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void copySign(const APFloat &RHS) {
1056c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (isNegative() != RHS.isNegative())
1057c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      changeSign();
1058c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1059c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1060c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// A static helper to produce a copy of an APFloat value with its sign
1061c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// copied from some other APFloat.
1062c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static APFloat copySign(APFloat Value, const APFloat &Sign) {
1063c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    Value.copySign(Sign);
1064c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return Value;
1065c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1066c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1067c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convert(const fltSemantics &ToSemantics, roundingMode RM,
1068c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                   bool *losesInfo);
1069c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertToInteger(MutableArrayRef<integerPart> Input,
1070c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                            unsigned int Width, bool IsSigned, roundingMode RM,
1071c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                            bool *IsExact) const {
1072c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFLOAT_DISPATCH_ON_SEMANTICS(
1073c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        convertToInteger(Input, Width, IsSigned, RM, IsExact));
1074c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1075c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertToInteger(APSInt &Result, roundingMode RM,
1076c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                            bool *IsExact) const;
1077c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertFromAPInt(const APInt &Input, bool IsSigned,
1078c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                            roundingMode RM) {
1079c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFLOAT_DISPATCH_ON_SEMANTICS(convertFromAPInt(Input, IsSigned, RM));
1080c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1081c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertFromSignExtendedInteger(const integerPart *Input,
1082c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          unsigned int InputSize, bool IsSigned,
1083c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          roundingMode RM) {
1084c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFLOAT_DISPATCH_ON_SEMANTICS(
1085c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        convertFromSignExtendedInteger(Input, InputSize, IsSigned, RM));
1086c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1087c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertFromZeroExtendedInteger(const integerPart *Input,
1088c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          unsigned int InputSize, bool IsSigned,
1089c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          roundingMode RM) {
1090c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFLOAT_DISPATCH_ON_SEMANTICS(
1091c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        convertFromZeroExtendedInteger(Input, InputSize, IsSigned, RM));
1092c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1093c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  opStatus convertFromString(StringRef, roundingMode);
1094c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APInt bitcastToAPInt() const {
1095c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFLOAT_DISPATCH_ON_SEMANTICS(bitcastToAPInt());
1096c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1097c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  double convertToDouble() const { return getIEEE().convertToDouble(); }
1098c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  float convertToFloat() const { return getIEEE().convertToFloat(); }
1099c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1100c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool operator==(const APFloat &) const = delete;
1101c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1102c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  cmpResult compare(const APFloat &RHS) const {
1103c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    assert(&getSemantics() == &RHS.getSemantics() &&
1104c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot           "Should only compare APFloats with the same semantics");
1105c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<IEEEFloat>(getSemantics()))
1106c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.IEEE.compare(RHS.U.IEEE);
1107c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<DoubleAPFloat>(getSemantics()))
1108c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.Double.compare(RHS.U.Double);
1109c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Unexpected semantics");
1110c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1111c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1112c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool bitwiseIsEqual(const APFloat &RHS) const {
1113c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (&getSemantics() != &RHS.getSemantics())
1114c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return false;
1115c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<IEEEFloat>(getSemantics()))
1116c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.IEEE.bitwiseIsEqual(RHS.U.IEEE);
1117c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (usesLayout<DoubleAPFloat>(getSemantics()))
1118c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return U.Double.bitwiseIsEqual(RHS.U.Double);
1119c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Unexpected semantics");
1120c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1121c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1122c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// We don't rely on operator== working on double values, as
1123c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1124c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// As such, this method can be used to do an exact bit-for-bit comparison of
1125c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// two floating point values.
1126c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1127c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// We leave the version with the double argument here because it's just so
1128c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// convenient to write "2.0" and the like.  Without this function we'd
1129c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// have to duplicate its logic everywhere it's called.
1130c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isExactlyValue(double V) const {
1131c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    bool ignored;
1132c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFloat Tmp(V);
1133c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    Tmp.convert(getSemantics(), APFloat::rmNearestTiesToEven, &ignored);
1134c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return bitwiseIsEqual(Tmp);
1135c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1136c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1137c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned int convertToHexString(char *DST, unsigned int HexDigits,
1138c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                  bool UpperCase, roundingMode RM) const {
1139c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFLOAT_DISPATCH_ON_SEMANTICS(
1140c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        convertToHexString(DST, HexDigits, UpperCase, RM));
1141c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1142c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1143c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isZero() const { return getCategory() == fcZero; }
1144c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isInfinity() const { return getCategory() == fcInfinity; }
1145c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isNaN() const { return getCategory() == fcNaN; }
1146c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1147c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isNegative() const { return getIEEE().isNegative(); }
1148c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isDenormal() const { APFLOAT_DISPATCH_ON_SEMANTICS(isDenormal()); }
1149c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isSignaling() const { return getIEEE().isSignaling(); }
1150c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1151c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isNormal() const { return !isDenormal() && isFiniteNonZero(); }
1152c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isFinite() const { return !isNaN() && !isInfinity(); }
1153c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1154c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  fltCategory getCategory() const { return getIEEE().getCategory(); }
1155c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const fltSemantics &getSemantics() const { return *U.semantics; }
1156c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isNonZero() const { return !isZero(); }
1157c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isFiniteNonZero() const { return isFinite() && !isZero(); }
1158c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isPosZero() const { return isZero() && !isNegative(); }
1159c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isNegZero() const { return isZero() && isNegative(); }
1160c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isSmallest() const { APFLOAT_DISPATCH_ON_SEMANTICS(isSmallest()); }
1161c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isLargest() const { APFLOAT_DISPATCH_ON_SEMANTICS(isLargest()); }
1162c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isInteger() const { APFLOAT_DISPATCH_ON_SEMANTICS(isInteger()); }
1163c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1164c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APFloat &operator=(const APFloat &RHS) = default;
1165c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  APFloat &operator=(APFloat &&RHS) = default;
1166c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1167c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision = 0,
1168c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                unsigned FormatMaxPadding = 3, bool TruncateZero = true) const {
1169c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFLOAT_DISPATCH_ON_SEMANTICS(
1170c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero));
1171c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1172c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1173c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void print(raw_ostream &) const;
1174c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void dump() const;
1175c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1176c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool getExactInverse(APFloat *inv) const {
1177c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    APFLOAT_DISPATCH_ON_SEMANTICS(getExactInverse(inv));
1178c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1179c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1180c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend hash_code hash_value(const APFloat &Arg);
1181c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend int ilogb(const APFloat &Arg) { return ilogb(Arg.getIEEE()); }
1182c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend APFloat scalbn(APFloat X, int Exp, roundingMode RM);
1183c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM);
1184c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend IEEEFloat;
1185c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend DoubleAPFloat;
1186c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot};
1187c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1188c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// See friend declarations above.
1189c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
1190c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// These additional declarations are required in order to compile LLVM with IBM
1191c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// xlC compiler.
1192c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robothash_code hash_value(const APFloat &Arg);
1193c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotinline APFloat scalbn(APFloat X, int Exp, APFloat::roundingMode RM) {
1194c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  if (APFloat::usesLayout<detail::IEEEFloat>(X.getSemantics()))
1195c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return APFloat(scalbn(X.U.IEEE, Exp, RM), X.getSemantics());
1196c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  if (APFloat::usesLayout<detail::DoubleAPFloat>(X.getSemantics()))
1197c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return APFloat(scalbn(X.U.Double, Exp, RM), X.getSemantics());
1198c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  llvm_unreachable("Unexpected semantics");
1199c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}
1200c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1201c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Equivalent of C standard library function.
1202c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
1203c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// While the C standard says Exp is an unspecified value for infinity and nan,
1204c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// this returns INT_MAX for infinities, and INT_MIN for NaNs.
1205c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotinline APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM) {
1206c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  if (APFloat::usesLayout<detail::IEEEFloat>(X.getSemantics()))
1207c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return APFloat(frexp(X.U.IEEE, Exp, RM), X.getSemantics());
1208c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  if (APFloat::usesLayout<detail::DoubleAPFloat>(X.getSemantics()))
1209c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return APFloat(frexp(X.U.Double, Exp, RM), X.getSemantics());
1210c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  llvm_unreachable("Unexpected semantics");
1211c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}
1212c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Returns the absolute value of the argument.
1213c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotinline APFloat abs(APFloat X) {
1214c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  X.clearSign();
1215c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  return X;
1216c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}
1217c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1218c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief Returns the negated value of the argument.
1219c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotinline APFloat neg(APFloat X) {
1220c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  X.changeSign();
1221c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  return X;
1222c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}
1223c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1224c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Implements IEEE minNum semantics. Returns the smaller of the 2 arguments if
1225c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// both are not NaN. If either argument is a NaN, returns the other argument.
1226c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotLLVM_READONLY
1227c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotinline APFloat minnum(const APFloat &A, const APFloat &B) {
1228c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  if (A.isNaN())
1229c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return B;
1230c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  if (B.isNaN())
1231c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return A;
1232c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  return (B.compare(A) == APFloat::cmpLessThan) ? B : A;
1233c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}
1234c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1235c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Implements IEEE maxNum semantics. Returns the larger of the 2 arguments if
1236c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// both are not NaN. If either argument is a NaN, returns the other argument.
1237c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotLLVM_READONLY
1238c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotinline APFloat maxnum(const APFloat &A, const APFloat &B) {
1239c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  if (A.isNaN())
1240c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return B;
1241c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  if (B.isNaN())
1242c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return A;
1243c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  return (A.compare(B) == APFloat::cmpLessThan) ? B : A;
1244c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}
1245c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1246c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} // namespace llvm
1247c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1248c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#undef APFLOAT_DISPATCH_ON_SEMANTICS
1249c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#endif // LLVM_ADT_APFLOAT_H
1250