Page MenuHomePhabricator

[libc] add basic strtold implementation
ClosedPublic

Authored by michaelrj on Nov 11 2021, 1:19 PM.

Details

Summary

Due to the differences between the types of long double, this function
is effectively three functions in one. This patch adds basic support for
the types of long double, although it's just using the fast path and the
fallback for the moment. I still need to implement a version of
Eisel-Lemire for performance, but the existing algorithms should be
correct.

Diff Detail

Event Timeline

michaelrj created this revision.Nov 11 2021, 1:19 PM
michaelrj requested review of this revision.Nov 11 2021, 1:19 PM
lntue accepted this revision.Nov 11 2021, 3:46 PM
lntue added inline comments.
libc/src/__support/str_to_float.h
390

Will the literal constant 1e23L work correctly for this?

397

You should add the suffix -L for the constant just in case the literal is converted to double before long double.

448

Check if the literal 1e23L, ... work properly.

456

Add suffix -L for the literal.

This revision is now accepted and ready to land.Nov 11 2021, 3:46 PM
michaelrj updated this revision to Diff 386682.Nov 11 2021, 4:32 PM
michaelrj marked 4 inline comments as done.

fix constants to properly use long doubles

sivachandra accepted this revision.Nov 12 2021, 4:54 PM
sivachandra added inline comments.
libc/src/__support/str_to_float.h
71

User reference arguments. Also, the name of this function should probably be setImplicitBit so that it is easy to explain/understand the NOP nature for IEEE-754 encodings.

libc/test/src/stdlib/strtold_test.cpp
26

May be I am missing something but I don't seem to find tests with different 64-bit, 80-bit and 128-bit errno. If they are missing, can we add them?

michaelrj updated this revision to Diff 387437.Nov 15 2021, 4:26 PM
michaelrj marked 2 inline comments as done.

fix inf rounding error and add a few tests. I'm planning on adding more, but I have other priority projects right now.

michaelrj added inline comments.Nov 16 2021, 11:34 AM
libc/test/src/stdlib/strtold_test.cpp
26

I've added tests with different errno behavior for the different sizes.

lntue accepted this revision.Nov 16 2021, 4:48 PM
michaelrj updated this revision to Diff 392509.Dec 7 2021, 1:03 PM

rebase for new formatting changes

michaelrj updated this revision to Diff 393614.Dec 10 2021, 3:45 PM

add a last round of tests before landing

This revision was automatically updated to reflect the committed changes.