[PATCH] D34518: [ADT] Add llvm::to_float

Pavel Labath via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 23 03:34:27 PDT 2017


labath added a comment.

In https://reviews.llvm.org/D34518#788213, @efriedma wrote:

> > it looks like it doesn't easily support long double
>
> APFloat::convertFromString works for every floating-point type supported by APFloat; clang uses it to parse floating-point literals.  There isn't any convenient way to convert an APFloat to a long double, but that's mostly because there hasn't been any demand for it; the format of long double is platform-dependent.


I don't actually need long double support right now -- I just added it because it was easy.

So the lack of long double would not be a show-stopper for using an APFloat-based solution. However, the convertFromString seems to assume that the input string has already been checked for correctness, as it is full of asserts. This means it's impossible to use it as a drop in replacement for the "parse me this string I got from the user" type of functionality, which is what the existing users of strtod do, and what I intended to use it for. That could of course be fixed, but given that we don't need the fancy features of APFloat here, and strtod is readily available everywhere, I am not sure if it's really worth it.


https://reviews.llvm.org/D34518





More information about the llvm-commits mailing list