[llvm] [IR][AsmParser] Revamp how floating-point literals work in LLVM IR. (PR #121838)
Joshua Cranmer via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 15 08:36:45 PST 2025
================
@@ -4595,11 +4595,13 @@ Simple Constants
zeros. So '``s0x0001``' of type '``i16``' will be -1, not 1.
**Floating-point constants**
Floating-point constants use standard decimal notation (e.g.
- 123.421), exponential notation (e.g. 1.23421e+2), or a more precise
- hexadecimal notation (see below). The assembler requires the exact
- decimal value of a floating-point constant. For example, the
- assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating
- decimal in binary. Floating-point constants must have a
+ 123.421), exponential notation (e.g. 1.23421e+2), standard hexadecimal
+ notation (e.g., 0x1.3effp-43), one of several special values, or a
+ precise bitstring for the underlying value. When converting decimal and
+ hexadecimal literals to the floating-point type, the value is converted
+ using the default rounding mode (round to nearest, half to even). String
+ conversions that underflow to 0 or overflow to infinity are not permitted.
----------------
jcranmer-intel wrote:
My main motivation was to keep the parsing code as strict as possible, so that if you saw a constant in the code, you could be certain you knew what it was. Despite the existing documentation, we already allow inexact conversions from decimal strings to `double` (we check for exactness on conversion of the resulting `double` to the actual type, though).
There's an argument to be made that allowing `0.1` as a constant, even if we didn't already allow it; I don't see a strong argument for allowing `1e99999` or `1e-99999` when we have easy syntax for infinity already.
https://github.com/llvm/llvm-project/pull/121838
More information about the llvm-commits
mailing list