This is an archive of the discontinued LLVM Phabricator instance.

Add StringRef::getAsDouble
ClosedPublic

Authored by zturner on Feb 13 2017, 5:11 PM.

Details

Summary

It's fairly cumbersome to figure out the correct way to do this if you're not familiar with the intricacies of APFloat, so hopefully this can help simplify the process, and it is in the same spirit as our getAsInteger set of functions.

I didn't add a detailed set of tests, because these are already pretty well tested in APFloatTest.cpp, only the most basic cases.

Diff Detail

Repository
rL LLVM

Event Timeline

zturner created this revision.Feb 13 2017, 5:11 PM
mehdi_amini added inline comments.Feb 13 2017, 5:15 PM
llvm/include/llvm/ADT/StringRef.h
517 ↗(On Diff #88282)

doc for public API?

llvm/lib/Support/StringRef.cpp
604 ↗(On Diff #88282)

fuse the two if?

zturner updated this revision to Diff 88284.Feb 13 2017, 5:19 PM
zturner added inline comments.
llvm/lib/Support/StringRef.cpp
604 ↗(On Diff #88282)

If I fuse the two if it's going to be wrapped by clang-format anyway, and I thought this made it clearer to read. But I can do it either way, LMK if you still want me to.

mehdi_amini accepted this revision.Feb 13 2017, 5:29 PM

LGTM.

llvm/include/llvm/ADT/StringRef.h
567 ↗(On Diff #88284)

I'd insert the declaration here, after all the integer related ones.

Also shouldn't we have a consumeDouble for symmetry with the integer case?

llvm/lib/Support/StringRef.cpp
604 ↗(On Diff #88282)

Do as you prefer, I don't think we have an official guidelines on this (it'd save the braces though).

This revision is now accepted and ready to land.Feb 13 2017, 5:29 PM
zturner added inline comments.Feb 13 2017, 5:35 PM
llvm/include/llvm/ADT/StringRef.h
567 ↗(On Diff #88284)

Probably so, but it's a bit tricky. Right now the API does not have any means to return parse error information back up to the caller, which is why I documented in the doc comment "string must be a well-formed double". I'd like to fix that though, so that we can return false when the string contains invalid characters.

That kind of API change would be necessary before we can think about stopping at the first invalid character.

This revision was automatically updated to reflect the committed changes.