aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ADT/APFloatTest.cpp
AgeCommit message (Collapse)AuthorFilesLines
2021-05-21[APFloat] convertToDouble/Float can work on shorter typesSerge Pavlov1-2/+259
Previously APFloat::convertToDouble may be called only for APFloats that were built using double semantics. Other semantics like single precision were not allowed although corresponding numbers could be converted to double without loss of precision. The similar restriction applied to APFloat::convertToFloat. With this change any APFloat that can be precisely represented by double can be handled with convertToDouble. Behavior of convertToFloat was updated similarly. It make the conversion operations more convenient and adds support for formats like half and bfloat. Differential Revision: https://reviews.llvm.org/D102671
2020-10-01[APFloat] convert SNaN to QNaN in convert() and raise Invalid signalSanjay Patel1-6/+8
This is an alternate fix (see D87835) for a bug where a NaN constant gets wrongly transformed into Infinity via truncation. In this patch, we uniformly convert any SNaN to QNaN while raising 'invalid op'. But we don't have a way to directly specify a 32-bit SNaN value in LLVM IR, so those are always encoded/decoded by calling convert from/to 64-bit hex. See D88664 for a clang fix needed to allow this change. Differential Revision: https://reviews.llvm.org/D88238
2020-09-30Patch IEEEFloat::isSignificandAllZeros and IEEEFloat::isSignificandAllOnes ↵Craig Topper1-0/+11
(bug 34579) Patch IEEEFloat::isSignificandAllZeros and IEEEFloat::isSignificandAllOnes to behave correctly in the case that the size of the significand is a multiple of the width of the integerParts making up the significand. The patch to IEEEFloat::isSignificandAllOnes fixes bug 34579, and the patch to IEEE:Float:isSignificandAllZeros fixes the unit test "APFloatTest.x87Next" I added here. I have included both in this diff since the changes are very similar. Patch by Andrew Briand
2020-09-24[APFloat] prevent NaN morphing into Inf on conversion (PR43907)Sanjay Patel1-2/+3
We shift the significand right on a truncation, but that needs to be made NaN-safe: always set at least 1 bit in the significand. https://llvm.org/PR43907 See D88238 for the likely follow-up (but needs some plumbing fixes before it can proceed). Differential Revision: https://reviews.llvm.org/D87835
2020-09-24[APFloat] add tests for convert of NAN; NFCSanjay Patel1-2/+16
More coverage for the bug fix proposed in D87835.
2020-03-11Make IEEEFloat::roundToIntegral more standard conformantSerge Pavlov1-0/+118
Behavior of IEEEFloat::roundToIntegral is aligned with IEEE-754 operation roundToIntegralExact. In partucular this function now: - returns opInvalid for signaling NaNs, - returns opInexact if the result of rounding differs from argument. Differential Revision: https://reviews.llvm.org/D75246
2020-03-06[APFloat] Overload comparison operatorsJay Foad1-0/+65
Summary: These implement the usual IEEE-style floating point comparison semantics, e.g. +0.0 == -0.0 and all operators except != return false if either argument is NaN. Subscribers: arsenm, jvesely, nhaehnle, hiraditya, dexonsmith, kerbowa, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75237
2020-03-06[APFloat] Overload unary operator-Jay Foad1-0/+11
Summary: We already have overloaded binary arithemetic operators so you can write A+B etc. This patch lets you write -A instead of neg(A). Subscribers: hiraditya, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75236
2020-02-12[APFloat] Fix FP remainder operationEhud Katz1-0/+438
Reimplement IEEEFloat::remainder() function. Fix PR3359. Differential Revision: https://reviews.llvm.org/D69776
2020-01-21[APFloat][unittest] Fix -Wsign-compare after D69773Fangrui Song1-1/+1
2020-01-21[APFloat] Add support for operations on Signaling NaNEhud Katz1-322/+132
Fix PR30781 Differential Revision: https://reviews.llvm.org/D69774
2020-01-21[APFloat][unittest] Fix -Wunused-variable after D69773Fangrui Song1-1/+0
2020-01-21[APFloat] Extend conversion from special stringsEhud Katz1-0/+114
Add support for converting Signaling NaN, and a NaN Payload from string. The NaNs (the string "nan" or "NaN") may be prefixed with 's' or 'S' for defining a Signaling NaN. A payload for a NaN can be specified as a suffix. It may be a octal/decimal/hexadecimal number in parentheses or without. Differential Revision: https://reviews.llvm.org/D69773
2020-01-09[APFloat] Fix checked error assert failuresEhud Katz1-4/+7
`APFLoat::convertFromString` returns `Expected` result, which must be "checked" if the LLVM_ENABLE_ABI_BREAKING_CHECKS preprocessor flag is set. To mark an `Expected` result as "checked" we must consume the `Error` within. In many cases, we are only interested in knowing if an error occured, without the need to examine the error info. This is achieved, easily, with the `errorToBool()` API.
2020-01-07[APFloat] Fix fusedMultiplyAdd when `this` equals to `Addend`Ehud Katz1-0/+8
Up until now, the arguments to `fusedMultiplyAdd` are passed by reference. We must save the `Addend` value on the beginning of the function, before we modify `this`, as they may be the same reference. To fix this, we now pass the `addend` parameter of `multiplySignificand` by value (instead of by-ref), and have a default value of zero. Fix PR44051. Differential Revision: https://reviews.llvm.org/D70422
2020-01-06[APFloat] Fix compilation warningsEhud Katz1-20/+6
2020-01-06[APFloat] Add recoverable string parsing errors to APFloatEhud Katz1-122/+130
Implementing the APFloat part in PR4745. Differential Revision: https://reviews.llvm.org/D69770
2019-12-04[APFloat] Prevent construction of APFloat with Semantics and FP valueEhud Katz1-13/+13
Constructor invocations such as `APFloat(APFloat::IEEEdouble(), 0.0)` may seem like they accept a FP (floating point) value, but the overload they reach is actually the `integerPart` one, not a `float` or `double` overload (which only exists when `fltSemantics` isn't passed). This may lead to possible loss of data, by the conversion from `float` or `double` to `integerPart`. To prevent future mistakes, a new constructor overload, which accepts any FP value and marked with `delete`, to prevent its usage. Fixes PR34095. Differential Revision: https://reviews.llvm.org/D70425
2019-11-22[APFloat] Enlarge ExponentType to 32bit integerEhud Katz1-15/+117
Enlarge the size of ExponentType from 16bit integer to 32bit. This is required to prevent exponent overflow/underflow. Note that IEEEFloat size and alignment don't change in 64bit or 32bit compilation targets (and in turn, neither does APFloat). Fixes PR34851. Differential Revision: https://reviews.llvm.org/D69771
2019-11-22[APFloat] Fix subtraction of subnormal numbersEhud Katz1-0/+9
Fix incorrect determination of the bigger number out of the two subtracted, while subnormal numbers are involved. Fixes PR44010. Differential Revision: https://reviews.llvm.org/D69772
2019-03-28[MC] Fix floating-point literal lexing.Eli Friedman1-30/+27
This patch has three related fixes to improve float literal lexing: 1. Make AsmLexer::LexDigit handle floats without a decimal point more consistently. 2. Make AsmLexer::LexFloatLiteral print an error for floats which are apparently missing an "e". 3. Make APFloat::convertFromString use binutils-compatible exponent parsing. Together, this fixes some cases where a float would be incorrectly rejected, fixes some cases where the compiler would crash, and improves diagnostics in some cases. Patch by Brandon Jones. Differential Revision: https://reviews.llvm.org/D57321 llvm-svn: 357214
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-12-10APFloat: allow 64-bit of payloadJF Bastien1-22/+38
Summary: The APFloat and Constant APIs taking an APInt allow arbitrary payloads, and that's great. There's a convenience API which takes an unsigned, and that's silly because it then directly creates a 64-bit APInt. Just change it to 64-bits directly. At the same time, add ConstantFP NaN getters which match the APFloat ones (with getQNaN / getSNaN and APInt parameters). Improve the APFloat testing to set more payload bits. Reviewers: scanon, rjmccall Subscribers: jkorous, dexonsmith, kristina, llvm-commits Differential Revision: https://reviews.llvm.org/D55460 llvm-svn: 348791
2018-10-13[Intrinsic] Add llvm.minimum and llvm.maximum instrinsic functionsThomas Lively1-0/+30
Summary: These new intrinsics have the semantics of the `minimum` and `maximum` operations specified by the latest draft of IEEE 754-2018. Unlike llvm.minnum and llvm.maxnum, these new intrinsics propagate NaNs and always treat -0.0 as less than 0.0. `minimum` and `maximum` lower directly to the existing `fminnan` and `fmaxnan` ISel DAG nodes. It is safe to reuse these DAG nodes because before this patch were only emitted in situations where there were known to be no NaN arguments or where NaN propagation was correct and there were known to be no zero arguments. I know of only four backends that lower fminnan and fmaxnan: WebAssembly, ARM, AArch64, and SystemZ, and each of these lowers fminnan and fmaxnan to instructions that are compatible with the IEEE 754-2018 semantics. Reviewers: aheejin, dschuff, sunfish, javed.absar Subscribers: kristof.beyls, dexonsmith, kristina, llvm-commits Differential Revision: https://reviews.llvm.org/D52764 llvm-svn: 344437
2018-05-09APFloat/x87: Fix string conversion for "unnormal" values (pr35860)Pavel Labath1-0/+7
Summary: Unnormal values are a feature of some very old x87 processors. We handle them correctly for the most part -- the only exception was an unnormal value whose significand happened to be zero. In this case the APFloat was still initialized as normal number (category = fcNormal), but a subsequent toString operation would assert because the math would produce nonsensical values for the zero significand. During review, it was decided that the correct way to fix this is to treat all unnormal values as NaNs (as that is what any >=386 processor will do). The issue was discovered because LLDB would crash when trying to print some "long double" values. Reviewers: skatkov, scanon, gottesmm Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D41868 llvm-svn: 331884
2017-12-19Fix APFloat from string conversion for InfSerguei Katkov1-0/+17
The method IEEEFloat::convertFromStringSpecials() does not recognize the "+Inf" and "-Inf" strings but these strings are printed for the double Infinities by the IEEEFloat::toString(). This patch adds the "+Inf" and "-Inf" strings to the list of recognized patterns in IEEEFloat::convertFromStringSpecials(). Re-landing after fix. Reviewers: sberg, bogner, majnemer, timshen, rnk, skatkov, gottesmm, bkramer, scanon, anna Reviewed By: anna Subscribers: mkazantsev, FlameTop, llvm-commits, reames, apilipenko Differential Revision: https://reviews.llvm.org/D38030 llvm-svn: 321054
2017-11-01Fix APFloat mod signSerguei Katkov1-0/+14
fmod specification requires the sign of the remainder is the same as numerator in case remainder is zero. Reviewers: gottesmm, scanon, arsenm, davide, craig.topper Reviewed By: scanon Subscribers: wdng, llvm-commits Differential Revision: https://reviews.llvm.org/D39225 llvm-svn: 317081
2017-10-19Revert rL316156 due to failure on APFloatTest.fromToStringSpecialsMax Kazantsev1-16/+0
llvm-svn: 316158
2017-10-19Fix APFloat from string conversion for InfSerguei Katkov1-0/+16
The method IEEEFloat::convertFromStringSpecials() does not recognize the "+Inf" and "-Inf" strings but these strings are printed for the double Infinities by the IEEEFloat::toString(). This patch adds the "+Inf" and "-Inf" strings to the list of recognized patterns in IEEEFloat::convertFromStringSpecials(). Reviewers: sberg, bogner, majnemer, timshen, rnk, skatkov, gottesmm, bkramer, scanon Reviewed By: skatkov Subscribers: apilipenko, reames, llvm-commits Differential Revision: https://reviews.llvm.org/D38030 llvm-svn: 316156
2017-10-18Untabify.NAKAMURA Takumi1-2/+2
llvm-svn: 316079
2017-08-28Untabify.NAKAMURA Takumi1-1/+1
llvm-svn: 311875
2017-08-21[APFloat] Fix IsInteger() for DoubleAPFloat.Davide Italiano1-0/+18
Previously, we would just assert instead. Differential Revision: https://reviews.llvm.org/D36961 llvm-svn: 311351
2017-07-10[ADT] Fix another "oops" spotted by eddyb and reported in IRC.Chandler Carruth1-1/+1
This test pretty clearly should be calling 'maxnum' here. =] llvm-svn: 307519
2017-07-09[ADT] Fix a test case to use a correct escape for a null byte followedChandler Carruth1-7/+7
by a valid octal digit. The length argument shows that this was in fact the intent. This was pointed out in IRC, thanks to eddyb! llvm-svn: 307496
2017-04-21[AsmWriter/APFloat] FP constant printing: Avoid usage of locale dependent ↵Serguei Katkov1-2/+19
snprinf This should fix the bug https://bugs.llvm.org/show_bug.cgi?id=12906 To print the FP constant AsmWriter does the following: 1) convert FP value to String (actually using snprintf function which is locale dependent). 2) Convert String back to FP Value 3) Compare original and got FP values. If they are not equal just dump as hex. The problem happens on the 2nd step when APFloat does not expect group delimiter or fraction delimiter other than period symbol and so on, which can be produced on the first step if LLVM library is used in an environment with corresponding locale set. To fix this issue the locale independent APFloat:toString function is used. However it prints FP values slightly differently than snprintf does. Specifically it suppress trailing zeros in significant, use capital E and so on. It results in 117 test failures during make check. To avoid this I've also updated APFloat.toString a bit to pass make check at least. Reviewers: sberg, bogner, majnemer, sanjoy, timshen, rnk Reviewed By: timshen, rnk Subscribers: rnk, llvm-commits Differential Revision: https://reviews.llvm.org/D32276 llvm-svn: 300943
2017-03-31Fix 80-column violation in previous commit.Stephen Canon1-1/+2
llvm-svn: 299257
2017-03-31Fix APFloat mod (committing for simonbyrne)Stephen Canon1-2/+65
The previous version was prone to intermediate rounding or overflow. Differential Revision: https://reviews.llvm.org/D29346 llvm-svn: 299256
2017-01-25DAGCombiner: Allow negating ConstantFP after legalizeMatt Arsenault1-0/+22
llvm-svn: 293019
2017-01-24[APFloat] Add PPCDoubleDouble multiplicationTim Shen1-34/+173
Reviewers: echristo, hfinkel, kbarton, iteratee Subscribers: mehdi_amini, llvm-commits Differential Revision: https://reviews.llvm.org/D28382 llvm-svn: 292860
2017-01-23[APFloat] Switch from (PPCDoubleDoubleImpl, IEEEdouble) layout to ↵Tim Shen1-17/+114
(IEEEdouble, IEEEdouble) Summary: This patch changes the layout of DoubleAPFloat, and adjust all operations to do either: 1) (IEEEdouble, IEEEdouble) -> (uint64_t, uint64_t) -> PPCDoubleDoubleImpl, then run the old algorithm. 2) Do the right thing directly. 1) includes multiply, divide, remainder, mod, fusedMultiplyAdd, roundToIntegral, convertFromString, next, convertToInteger, convertFromAPInt, convertFromSignExtendedInteger, convertFromZeroExtendedInteger, convertToHexString, toString, getExactInverse. 2) includes makeZero, makeLargest, makeSmallest, makeSmallestNormalized, compare, bitwiseIsEqual, bitcastToAPInt, isDenormal, isSmallest, isLargest, isInteger, ilogb, scalbn, frexp, hash_value, Profile. I could split this into two patches, e.g. use 1) for all operatoins first, then incrementally change some of them to 2). I didn't do that, because 1) involves code that converts data between PPCDoubleDoubleImpl and (IEEEdouble, IEEEdouble) back and forth, and may pessimize the compiler. Instead, I find easy functions and use approach 2) for them directly. Next step is to implement move multiply and divide from 1) to 2). I don't have plans for other functions in 1). Differential Revision: https://reviews.llvm.org/D27872 llvm-svn: 292839
2017-01-05[APFloatTest] Add tests for various operationsTim Shen1-4/+271
Differential Revision: https://reviews.llvm.org/D27833 llvm-svn: 291189
2016-12-16[APFloatTest] Log when test fails. NFCTim Shen1-7/+21
Reviewers: iteratee Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D27828 llvm-svn: 289904
2016-12-14Adapt to recent APFloat changeStephan Bergmann1-6/+6
llvm-svn: 289649
2016-12-14Replace APFloatBase static fltSemantics data members with getter functionsStephan Bergmann1-820/+820
At least the plugin used by the LibreOffice build (<https://wiki.documentfoundation.org/Development/Clang_plugins>) indirectly uses those members (through inline functions in LLVM/Clang include files in turn using them), but they are not exported by utils/extract_symbols.py on Windows, and accessing data across DLL/EXE boundaries on Windows is generally problematic. Differential Revision: https://reviews.llvm.org/D26671 llvm-svn: 289647
2016-12-12[APFloatTest] Use std::make_tuple to make GCC 4.8 happyTim Shen1-35/+38
Differential Revision: https://reviews.llvm.org/D26817 llvm-svn: 289474
2016-12-12[APFloat] Implement PPCDoubleDouble add and subtract.Tim Shen1-16/+119
Summary: I looked at libgcc's implementation (which is based on the paper, Software for Doubled-Precision Floating-Point Computations", by Seppo Linnainmaa, ACM TOMS vol 7 no 3, September 1981, pages 272-283.) and made it generic to arbitrary IEEE floats. Differential Revision: https://reviews.llvm.org/D26817 llvm-svn: 289472
2016-11-06[APFloat] Make functions that produce APFloaat objects use correct semantics.Tim Shen1-0/+28
Summary: Fixes PR30869. In D25977 I meant to change all functions that care about lifetime. I changed constructors, factory functions, but I missed member/free functions that return new instances. This patch changes them. Reviewers: hfinkel, kbarton, echristo, joerg Subscribers: llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D26269 llvm-svn: 286060
2016-04-18[NFC] Header cleanupMehdi Amini1-1/+0
Removed some unused headers, replaced some headers with forward class declarations. Found using simple scripts like this one: clear && ack --cpp -l '#include "llvm/ADT/IndexedMap.h"' | xargs grep -L 'IndexedMap[<]' | xargs grep -n --color=auto 'IndexedMap' Patch by Eugene Kosov <claprix@yandex.ru> Differential Revision: http://reviews.llvm.org/D19219 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 266595
2016-03-23APFloat: Fix signalling nans for scalbnMatt Arsenault1-1/+16
llvm-svn: 264219
2016-03-21APFloat: Add frexpMatt Arsenault1-1/+127
llvm-svn: 263950