APFloat.h revision fce7b6b5d9905bf35641ee7f001b6b66dbc26c2d
1b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner//== llvm/Support/APFloat.h - Arbitrary Precision Floating Point -*- C++ -*-==// 2b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner// 3b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner// The LLVM Compiler Infrastructure 4b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner// 57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source 67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details. 7b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner// 8b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner//===----------------------------------------------------------------------===// 9b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner// 10b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner// This file declares a class to represent arbitrary precision floating 11b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner// point values and provide a variety of arithmetic operations on them. 12b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner// 13b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner//===----------------------------------------------------------------------===// 14b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 15b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner/* A self-contained host- and target-independent arbitrary-precision 16a30b0ee959b53e83ed3697ee0b704a493829dc04Neil Booth floating-point software implementation. It uses bignum integer 17a30b0ee959b53e83ed3697ee0b704a493829dc04Neil Booth arithmetic as provided by static functions in the APInt class. 18b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner The library will work with bignum integers whose parts are any 19a30b0ee959b53e83ed3697ee0b704a493829dc04Neil Booth unsigned type at least 16 bits wide, but 64 bits is recommended. 20b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 21b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner Written for clarity rather than speed, in particular with a view 22b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner to use in the front-end of a cross compiler so that target 23b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner arithmetic can be correctly performed on the host. Performance 24b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner should nonetheless be reasonable, particularly for its intended 25b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner use. It may be useful as a base implementation for a run-time 26b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner library during development of a faster target-specific one. 27b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 28b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner All 5 rounding modes in the IEEE-754R draft are handled correctly 29b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner for all implemented operations. Currently implemented operations 30b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner are add, subtract, multiply, divide, fused-multiply-add, 31b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner conversion-to-float, conversion-to-integer and 32b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner conversion-from-integer. New rounding modes (e.g. away from zero) 33a30b0ee959b53e83ed3697ee0b704a493829dc04Neil Booth can be added with three or four lines of code. 34b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 35b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner Four formats are built-in: IEEE single precision, double 36b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner precision, quadruple precision, and x87 80-bit extended double 37b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner (when operating with full extended precision). Adding a new 38b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner format that obeys IEEE semantics only requires adding two lines of 39b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner code: a declaration and definition of the format. 40b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 41b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner All operations return the status of that operation as an exception 42b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner bit-mask, so multiple operations can be done consecutively with 43b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner their results or-ed together. The returned status can be useful 44b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner for compiler diagnostics; e.g., inexact, underflow and overflow 45b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner can be easily diagnosed on constant folding, and compiler 46b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner optimizers can determine what exceptions would be raised by 47b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner folding operations and optimize, or perhaps not optimize, 48b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner accordingly. 49b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 50b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner At present, underflow tininess is detected after rounding; it 51b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner should be straight forward to add support for the before-rounding 52b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner case too. 53b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 54a30b0ee959b53e83ed3697ee0b704a493829dc04Neil Booth The library reads hexadecimal floating point numbers as per C99, 55a30b0ee959b53e83ed3697ee0b704a493829dc04Neil Booth and correctly rounds if necessary according to the specified 56a30b0ee959b53e83ed3697ee0b704a493829dc04Neil Booth rounding mode. Syntax is required to have been validated by the 57a30b0ee959b53e83ed3697ee0b704a493829dc04Neil Booth caller. It also converts floating point numbers to hexadecimal 58a30b0ee959b53e83ed3697ee0b704a493829dc04Neil Booth text as per the C99 %a and %A conversions. The output precision 59a30b0ee959b53e83ed3697ee0b704a493829dc04Neil Booth (or alternatively the natural minimal precision) can be specified; 60a30b0ee959b53e83ed3697ee0b704a493829dc04Neil Booth if the requested precision is less than the natural precision the 61a30b0ee959b53e83ed3697ee0b704a493829dc04Neil Booth output is correctly rounded for the specified rounding mode. 62a30b0ee959b53e83ed3697ee0b704a493829dc04Neil Booth 6396c7471b39dc77d4f29658212e5a72e575b23c39Neil Booth It also reads decimal floating point numbers and correctly rounds 6496c7471b39dc77d4f29658212e5a72e575b23c39Neil Booth according to the specified rounding mode. 6596c7471b39dc77d4f29658212e5a72e575b23c39Neil Booth 6696c7471b39dc77d4f29658212e5a72e575b23c39Neil Booth Conversion to decimal text is not currently implemented. 67a30b0ee959b53e83ed3697ee0b704a493829dc04Neil Booth 68b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner Non-zero finite numbers are represented internally as a sign bit, 69b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner a 16-bit signed exponent, and the significand as an array of 70b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner integer parts. After normalization of a number of precision P the 71b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner exponent is within the range of the format, and if the number is 72b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner not denormal the P-th bit of the significand is set as an explicit 73b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner integer bit. For denormals the most significant bit is shifted 74b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner right so that the exponent is maintained at the format's minimum, 75b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner so that the smallest denormal has just the least significant bit 76b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner of the significand set. The sign of zeroes and infinities is 77117acf9e36a0789d56b52525e031f575f80fe169Neil Booth significant; the exponent and significand of such numbers is not 78117acf9e36a0789d56b52525e031f575f80fe169Neil Booth stored, but has a known implicit (deterministic) value: 0 for the 79117acf9e36a0789d56b52525e031f575f80fe169Neil Booth significands, 0 for zero exponent, all 1 bits for infinity 80117acf9e36a0789d56b52525e031f575f80fe169Neil Booth exponent. For NaNs the sign and significand are deterministic, 81117acf9e36a0789d56b52525e031f575f80fe169Neil Booth although not really meaningful, and preserved in non-conversion 82117acf9e36a0789d56b52525e031f575f80fe169Neil Booth operations. The exponent is implicitly all 1 bits. 83b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 84b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner TODO 85b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner ==== 86b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 87b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner Some features that may or may not be worth adding: 88b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 8996c7471b39dc77d4f29658212e5a72e575b23c39Neil Booth Binary to decimal conversion (hard). 90b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 91b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner Optional ability to detect underflow tininess before rounding. 92b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 93b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner New formats: x87 in single and double precision mode (IEEE apart 9496c7471b39dc77d4f29658212e5a72e575b23c39Neil Booth from extended exponent range) (hard). 95b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 96a30b0ee959b53e83ed3697ee0b704a493829dc04Neil Booth New operations: sqrt, IEEE remainder, C90 fmod, nextafter, 97a30b0ee959b53e83ed3697ee0b704a493829dc04Neil Booth nexttoward. 98b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner*/ 99b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 100674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#ifndef LLVM_ADT_APFLOAT_H 101674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#define LLVM_ADT_APFLOAT_H 102b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 103b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner// APInt contains static functions implementing bignum arithmetic. 104b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner#include "llvm/ADT/APInt.h" 105b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 106b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattnernamespace llvm { 107b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 108fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman/* Exponents are stored as signed numbers. */ 109fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesmantypedef signed short exponent_t; 110fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 111fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesmanstruct fltSemantics; 112fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesmanclass APSInt; 113fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesmanclass StringRef; 114fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 115fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman/* When bits of a floating point number are truncated, this enum is 116fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman used to indicate what fraction of the LSB those bits represented. 117fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman It essentially combines the roles of guard and sticky bits. */ 118fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesmanenum lostFraction { // Example of truncated bits: 119fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman lfExactlyZero, // 000000 120fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman lfLessThanHalf, // 0xxxxx x's not all zero 121fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman lfExactlyHalf, // 100000 122fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman lfMoreThanHalf // 1xxxxx x's not all zero 123fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman}; 124fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 125fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesmanclass APFloat { 126fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesmanpublic: 127fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 128fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* We support the following floating point semantics. */ 129fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static const fltSemantics IEEEhalf; 130fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static const fltSemantics IEEEsingle; 131fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static const fltSemantics IEEEdouble; 132fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static const fltSemantics IEEEquad; 133fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static const fltSemantics PPCDoubleDouble; 134fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static const fltSemantics x87DoubleExtended; 135fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* And this pseudo, used to construct APFloats that cannot 136fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman conflict with anything real. */ 137fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static const fltSemantics Bogus; 138fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 139fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static unsigned int semanticsPrecision(const fltSemantics &); 140fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 141fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* Floating point numbers have a four-state comparison relation. */ 142fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman enum cmpResult { 143fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman cmpLessThan, 144fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman cmpEqual, 145fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman cmpGreaterThan, 146fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman cmpUnordered 147b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner }; 148b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 149fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* IEEE-754R gives five rounding modes. */ 150fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman enum roundingMode { 151fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman rmNearestTiesToEven, 152fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman rmTowardPositive, 153fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman rmTowardNegative, 154fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman rmTowardZero, 155fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman rmNearestTiesToAway 156fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman }; 157e12b73816b50bbe2cc54b8005d86c95413b4f465John McCall 158fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman // Operation status. opUnderflow or opOverflow are always returned 159fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman // or-ed with opInexact. 160fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman enum opStatus { 161fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opOK = 0x00, 162fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opInvalidOp = 0x01, 163fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opDivByZero = 0x02, 164fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opOverflow = 0x04, 165fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opUnderflow = 0x08, 166fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opInexact = 0x10 167fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman }; 168e12b73816b50bbe2cc54b8005d86c95413b4f465John McCall 169fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman // Category of internally-represented number. 170fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman enum fltCategory { 171fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman fcInfinity, 172fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman fcNaN, 173fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman fcNormal, 174fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman fcZero 175fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman }; 1763a54b3dc87a581c203b18050b4f787b4ca28a12cMisha Brukman 177fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman enum uninitializedTag { 178fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman uninitialized 179b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner }; 1803a9b71434cda6f66d65a031effec1bbe58e1dda3Rafael Espindola 181fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman // Constructors. 182fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman APFloat(const fltSemantics &); // Default construct to 0.0 183fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman APFloat(const fltSemantics &, StringRef); 184fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman APFloat(const fltSemantics &, integerPart); 185fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman APFloat(const fltSemantics &, fltCategory, bool negative); 186fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman APFloat(const fltSemantics &, uninitializedTag); 187fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman APFloat(const fltSemantics &, const APInt &); 188fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman explicit APFloat(double d); 189fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman explicit APFloat(float f); 190fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman APFloat(const APFloat &); 191fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman ~APFloat(); 192fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 193fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman // Convenience "constructors" 194fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static APFloat getZero(const fltSemantics &Sem, bool Negative = false) { 195fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman return APFloat(Sem, fcZero, Negative); 196fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman } 197fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static APFloat getInf(const fltSemantics &Sem, bool Negative = false) { 198fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman return APFloat(Sem, fcInfinity, Negative); 199fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman } 200fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 201fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// getNaN - Factory for QNaN values. 202fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// 203fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// \param Negative - True iff the NaN generated should be negative. 204fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// \param type - The unspecified fill bits for creating the NaN, 0 by 205fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// default. The value is truncated as necessary. 206fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static APFloat getNaN(const fltSemantics &Sem, bool Negative = false, 207fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman unsigned type = 0) { 208fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman if (type) { 209fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman APInt fill(64, type); 210fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman return getQNaN(Sem, Negative, &fill); 211fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman } else { 212fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman return getQNaN(Sem, Negative, 0); 213fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman } 214fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman } 215fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 216fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// getQNan - Factory for QNaN values. 217fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static APFloat getQNaN(const fltSemantics &Sem, bool Negative = false, 218fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman const APInt *payload = 0) { 219fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman return makeNaN(Sem, false, Negative, payload); 220fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman } 221fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 222fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// getSNan - Factory for SNaN values. 223fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static APFloat getSNaN(const fltSemantics &Sem, bool Negative = false, 224fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman const APInt *payload = 0) { 225fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman return makeNaN(Sem, true, Negative, payload); 226fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman } 227fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 228fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// getLargest - Returns the largest finite number in the given 229fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// semantics. 230fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// 231fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// \param Negative - True iff the number should be negative 232fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static APFloat getLargest(const fltSemantics &Sem, bool Negative = false); 233fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 234fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// getSmallest - Returns the smallest (by magnitude) finite number 235fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// in the given semantics. Might be denormalized, which implies a 236fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// relative loss of precision. 237fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// 238fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// \param Negative - True iff the number should be negative 239fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static APFloat getSmallest(const fltSemantics &Sem, bool Negative = false); 240fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 241fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// getSmallestNormalized - Returns the smallest (by magnitude) 242fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// normalized finite number in the given semantics. 243fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// 244fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// \param Negative - True iff the number should be negative 245fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static APFloat getSmallestNormalized(const fltSemantics &Sem, 246fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool Negative = false); 247fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 248fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// getAllOnesValue - Returns a float which is bitcasted from 249fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// an all one value int. 250fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// 251fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// \param BitWidth - Select float type 252fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// \param isIEEE - If 128 bit number, select between PPC and IEEE 253fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static APFloat getAllOnesValue(unsigned BitWidth, bool isIEEE = false); 254fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 255fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// Profile - Used to insert APFloat objects, or objects that contain 256fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// APFloat objects, into FoldingSets. 257fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void Profile(FoldingSetNodeID &NID) const; 258fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 259fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// @brief Used by the Bitcode serializer to emit APInts to Bitcode. 260fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void Emit(Serializer &S) const; 261fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 262fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// @brief Used by the Bitcode deserializer to deserialize APInts. 263fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static APFloat ReadVal(Deserializer &D); 264fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 265fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* Arithmetic. */ 266fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus add(const APFloat &, roundingMode); 267fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus subtract(const APFloat &, roundingMode); 268fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus multiply(const APFloat &, roundingMode); 269fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus divide(const APFloat &, roundingMode); 270fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* IEEE remainder. */ 271fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus remainder(const APFloat &); 272fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* C fmod, or llvm frem. */ 273fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus mod(const APFloat &, roundingMode); 274fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus fusedMultiplyAdd(const APFloat &, const APFloat &, roundingMode); 275fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus roundToIntegral(roundingMode); 276fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 277fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* Sign operations. */ 278fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void changeSign(); 279fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void clearSign(); 280fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void copySign(const APFloat &); 281fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 282fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* Conversions. */ 283fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus convert(const fltSemantics &, roundingMode, bool *); 284fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus convertToInteger(integerPart *, unsigned int, bool, roundingMode, 285fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool *) const; 286fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus convertToInteger(APSInt &, roundingMode, bool *) const; 287fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus convertFromAPInt(const APInt &, bool, roundingMode); 288fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus convertFromSignExtendedInteger(const integerPart *, unsigned int, 289fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool, roundingMode); 290fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus convertFromZeroExtendedInteger(const integerPart *, unsigned int, 291fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool, roundingMode); 292fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus convertFromString(StringRef, roundingMode); 293fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman APInt bitcastToAPInt() const; 294fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman double convertToDouble() const; 295fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman float convertToFloat() const; 296fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 297fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* The definition of equality is not straightforward for floating point, 298fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman so we won't use operator==. Use one of the following, or write 299fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman whatever it is you really mean. */ 300fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool operator==(const APFloat &) const LLVM_DELETED_FUNCTION; 301fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 302fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* IEEE comparison with another floating point number (NaNs 303fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman compare unordered, 0==-0). */ 304fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman cmpResult compare(const APFloat &) const; 305fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 306fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* Bitwise comparison for equality (QNaNs compare equal, 0!=-0). */ 307fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool bitwiseIsEqual(const APFloat &) const; 308fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 309fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* Write out a hexadecimal representation of the floating point 310fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman value to DST, which must be of sufficient size, in the C99 form 311fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman [-]0xh.hhhhp[+-]d. Return the number of characters written, 312fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman excluding the terminating NUL. */ 313fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman unsigned int convertToHexString(char *dst, unsigned int hexDigits, 314fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool upperCase, roundingMode) const; 315fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 316fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* Simple queries. */ 317fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman fltCategory getCategory() const { return category; } 318fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman const fltSemantics &getSemantics() const { return *semantics; } 319fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool isZero() const { return category == fcZero; } 320fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool isNonZero() const { return category != fcZero; } 321fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool isNormal() const { return category == fcNormal; } 322fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool isNaN() const { return category == fcNaN; } 323fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool isInfinity() const { return category == fcInfinity; } 324fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool isNegative() const { return sign; } 325fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool isPosZero() const { return isZero() && !isNegative(); } 326fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool isNegZero() const { return isZero() && isNegative(); } 327fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool isDenormal() const; 328fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 329fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman APFloat &operator=(const APFloat &); 330fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 331fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// \brief Overload to compute a hash code for an APFloat value. 332fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// 333fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// Note that the use of hash codes for floating point values is in general 334fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// frought with peril. Equality is hard to define for these values. For 335fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// example, should negative and positive zero hash to different codes? Are 336fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// they equal or not? This hash value implementation specifically 337fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// emphasizes producing different codes for different inputs in order to 338fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// be used in canonicalization and memoization. As such, equality is 339fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// bitwiseIsEqual, and 0 != -0. 340fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman friend hash_code hash_value(const APFloat &Arg); 341fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 342fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// Converts this value into a decimal string. 343fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// 344fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// \param FormatPrecision The maximum number of digits of 345fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// precision to output. If there are fewer digits available, 346fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// zero padding will not be used unless the value is 347fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// integral and small enough to be expressed in 348fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// FormatPrecision digits. 0 means to use the natural 349fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// precision of the number. 350fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// \param FormatMaxPadding The maximum number of zeros to 351fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// consider inserting before falling back to scientific 352fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// notation. 0 means to always use scientific notation. 353fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// 354fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// Number Precision MaxPadding Result 355fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// ------ --------- ---------- ------ 356fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// 1.01E+4 5 2 10100 357fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// 1.01E+4 4 2 1.01E+4 358fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// 1.01E+4 5 1 1.01E+4 359fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// 1.01E-2 5 2 0.0101 360fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// 1.01E-2 4 2 0.0101 361fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// 1.01E-2 4 1 1.01E-2 362fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision = 0, 363fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman unsigned FormatMaxPadding = 3) const; 364fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 365fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// getExactInverse - If this value has an exact multiplicative inverse, 366fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /// store it in inv and return true. 367fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool getExactInverse(APFloat *inv) const; 368fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 369fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesmanprivate: 370fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 371fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* Trivial queries. */ 372fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman integerPart *significandParts(); 373fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman const integerPart *significandParts() const; 374fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman unsigned int partCount() const; 375fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 376fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* Significand operations. */ 377fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman integerPart addSignificand(const APFloat &); 378fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman integerPart subtractSignificand(const APFloat &, integerPart); 379fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman lostFraction addOrSubtractSignificand(const APFloat &, bool subtract); 380fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman lostFraction multiplySignificand(const APFloat &, const APFloat *); 381fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman lostFraction divideSignificand(const APFloat &); 382fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void incrementSignificand(); 383fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void initialize(const fltSemantics *); 384fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void shiftSignificandLeft(unsigned int); 385fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman lostFraction shiftSignificandRight(unsigned int); 386fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman unsigned int significandLSB() const; 387fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman unsigned int significandMSB() const; 388fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void zeroSignificand(); 389fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 390fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* Arithmetic on special values. */ 391fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus addOrSubtractSpecials(const APFloat &, bool subtract); 392fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus divideSpecials(const APFloat &); 393fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus multiplySpecials(const APFloat &); 394fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus modSpecials(const APFloat &); 395fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 396fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* Miscellany. */ 397fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman static APFloat makeNaN(const fltSemantics &Sem, bool SNaN, bool Negative, 398fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman const APInt *fill); 399fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void makeNaN(bool SNaN = false, bool Neg = false, const APInt *fill = 0); 400fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus normalize(roundingMode, lostFraction); 401fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus addOrSubtract(const APFloat &, roundingMode, bool subtract); 402fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman cmpResult compareAbsoluteValue(const APFloat &) const; 403fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus handleOverflow(roundingMode); 404fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman bool roundAwayFromZero(roundingMode, lostFraction, unsigned int) const; 405fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus convertToSignExtendedInteger(integerPart *, unsigned int, bool, 406fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman roundingMode, bool *) const; 407fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus convertFromUnsignedParts(const integerPart *, unsigned int, 408fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman roundingMode); 409fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus convertFromHexadecimalString(StringRef, roundingMode); 410fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus convertFromDecimalString(StringRef, roundingMode); 411fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman char *convertNormalToHexString(char *, unsigned int, bool, 412fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman roundingMode) const; 413fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman opStatus roundSignificandWithExponent(const integerPart *, unsigned int, int, 414fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman roundingMode); 415fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 416fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman APInt convertHalfAPFloatToAPInt() const; 417fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman APInt convertFloatAPFloatToAPInt() const; 418fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman APInt convertDoubleAPFloatToAPInt() const; 419fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman APInt convertQuadrupleAPFloatToAPInt() const; 420fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman APInt convertF80LongDoubleAPFloatToAPInt() const; 421fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman APInt convertPPCDoubleDoubleAPFloatToAPInt() const; 422fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void initFromAPInt(const fltSemantics *Sem, const APInt &api); 423fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void initFromHalfAPInt(const APInt &api); 424fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void initFromFloatAPInt(const APInt &api); 425fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void initFromDoubleAPInt(const APInt &api); 426fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void initFromQuadrupleAPInt(const APInt &api); 427fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void initFromF80LongDoubleAPInt(const APInt &api); 428fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void initFromPPCDoubleDoubleAPInt(const APInt &api); 429fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 430fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void assign(const APFloat &); 431fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void copySignificand(const APFloat &); 432fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman void freeSignificand(); 433fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 434fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* What kind of semantics does this value obey? */ 435fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman const fltSemantics *semantics; 436fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 437fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* Significand - the fraction with an explicit integer bit. Must be 438fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman at least one bit wider than the target precision. */ 439fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman union Significand { 440fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman integerPart part; 441fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman integerPart *parts; 442fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman } significand; 443fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 444fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* The exponent - a signed number. */ 445fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman exponent_t exponent; 446fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 447fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* What kind of floating point number this is. */ 448fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* Only 2 bits are required, but VisualStudio incorrectly sign extends 449fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman it. Using the extra bit keeps it from failing under VisualStudio */ 450fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman fltCategory category : 3; 451fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 452fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman /* The sign bit of this number. */ 453fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman unsigned int sign : 1; 454fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman}; 455fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman 456fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman// See friend declaration above. This additional declaration is required in 457fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesman// order to compile LLVM with IBM xlC compiler. 458fce7b6b5d9905bf35641ee7f001b6b66dbc26c2dMichael Gottesmanhash_code hash_value(const APFloat &Arg); 459b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner} /* namespace llvm */ 460b39cdde41d3c91d1fd48a038e63b78122607bb10Chris Lattner 461674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#endif /* LLVM_ADT_APFLOAT_H */ 462