This is an archive of the discontinued LLVM Phabricator instance.

[libc][NFC] Add supporting class for atof implementation
ClosedPublic

Authored by michaelrj on Sep 24 2021, 4:13 PM.

Details

Summary

This change adds the High Precision Decimal described here:
https://nigeltao.github.io/blog/2020/parse-number-f64-simple.html
It will be used for the atof implementation later, but is complete and
tested now.

The code is inspired by the golang implmentation of the HPD class, which
can be found here: https://github.com/golang/go/blob/release-branch.go1.16/src/strconv/decimal.go

Diff Detail

Event Timeline

michaelrj created this revision.Sep 24 2021, 4:13 PM
michaelrj requested review of this revision.Sep 24 2021, 4:13 PM
michaelrj updated this revision to Diff 375439.Sep 27 2021, 5:07 PM

parse the decimal point out of the string. This meant I needed to change the imports so I could use strtointeger for the integer parsing.

michaelrj updated this revision to Diff 376349.Sep 30 2021, 1:50 PM

update the comments and add a file to generate the constant table

michaelrj edited the summary of this revision. (Show Details)Sep 30 2021, 3:31 PM
sivachandra accepted this revision.Oct 4 2021, 10:52 AM
sivachandra added inline comments.
libc/src/__support/GenerateHPDConstants.py
1 ↗(On Diff #376349)

This file should go in https://github.com/llvm/llvm-project/tree/main/libc/utils/mathtools.

Also, please add a detailed doc comment about what this script is for.

libc/src/__support/high_precision_decimal.h
33

Add a note here that these constants were generated using the <link/to/the/script/in/utils/mathtools/>.

This revision is now accepted and ready to land.Oct 4 2021, 10:52 AM
michaelrj updated this revision to Diff 376999.Oct 4 2021, 12:29 PM
michaelrj marked 2 inline comments as done.

move the constant generation script and add an explanation of what it is and how it works.

libc/src/__support/GenerateHPDConstants.py
1 ↗(On Diff #376349)

I may have gone a bit overboard with this one, but I wanted to have a clear explanation of how and why this trick works. I can make it a bit shorter if you want.

sivachandra accepted this revision.Oct 4 2021, 12:35 PM
This revision was automatically updated to reflect the committed changes.