Skip to content
0:00 / 0:00

#charconv#floating-point#ryualgorithm

Stephan T. Lavavej “Floating-Point <charconv>: Making Your Code 10x Faster With C++17's Final Boss”

CppCon

189K subscribers • 103 videos on Hallway • Conference channel

YouTube
  • Recommended by 3 people: 3 on Hacker News.
  • Presented by Stephan T. Lavavej, software engineer at Microsoft
  • Linked in the descriptionCppCon/CppCon2019

Advanced. Deep dive for people who know the field.

40K views7 years ago3 recommendations

Systems programmingProgramming languagesC++Performance and optimizationAlgorithms

Stephan T. Lavavej explains the implementation of fast floating-point to-string and string-to-floating-point conversions in Microsoft's C++ standard library.

CppCon.org — Discussion & Comments: reddit.com/r/cpp/ — Presentation Slides, PDFs, Source Code and other presenter materials are available at: github.com/CppCon/CppCon2019 — Floating-point numbers are ancient, mysterious, and terrifying. Over the past 30 years, the C and C++ Standards have provided many functions for floating-point/string conversions, such as C's strtof(), strtod(), and printf() %a %e %f %g, and C++'s iostreams, stof(), stod(), and to_string(). Despite this history, floating-point is far from a solved problem - these functions have ranged from annoyingly to egregiously slow, and application developers and library maintainers alike have found it exceedingly difficult to understand floating-point behavior. This session will present new and wondrous developments in the area of floating-point conversions. If your serialization code is bottlenecked by floating-point printing, this will accelerate your code by roughly 3x to 30x (yes, times, not percent). You can also improve the human-readability of your output. Along the way, this session will cover the basics of floating-point representations, dispelling common myths like fuzziness and non-determinism. Specifically, C++17 added 3 pages of Standardese describing the charconv header and its functions from_chars() and to_chars(). This feature has required an unexpectedly large amount of implementation work, taking over a dev-year for MSVC and becoming the last C++17 library feature to ship. Coincidentally, Ulf Adams at Google developed a novel algorithm named Ryu, which is responsible for the amazing speed of to_chars(). This session will focus on how to use charconv and how to understand its many supported formats, with a brief overview of Ryu's techniques. — Stephan T. Lavavej Microsoft Principal Software Engineer Redmond, WA Stephan T. Lavavej is a Principal Software Engineer at Microsoft, maintaining Visual C++'s implementation of the C++ Standard Library since 2007. He also designed a couple of C++14 features: make_unique and the transparent operator functors. He likes his initials (which people can actually spell) and cats (although he doesn't own any). — Videos Filmed & Edited by Bash Films: BashFilms.com Work at Hudson River Trading (HRT): tinyurl.com/safxfctf

Why it's here

3 people recommend this

What people say. Recommended as an entertaining and deep dive into the complex algorithms behind high-performance floating-point conversions in C++.

Moments people linked to

Forricideon Hacker News • Recommends

On “C++20, How Hard Could It Be”

I really love this talk in particular: link to this video (On charconv) But any of the ones I've seen from Stephan have been fantastic, I think, although I'm not actually sure if I've seen more. He seems to have a lot of talks on very specific subjects, which can be really fun. > Hyrum Wright is in the audience yelling interjections as a result of Hyrum's law This sounds absolutely hilarious, I'll have to take a look.

osoloon Hacker News • Recommends

On “Parsing floats in C++: benchmarking strtod vs. from_chars”

For those interested in more information about performance was achieved, Stephan Lavavej gave a talk about this very subject during CppCon 2019 1. 1 link to this video

ygraon Hacker News • Recommends

On “Rendering floating numbers: advances in problems you didn’t know you had (2011)”

Stephan T Lavavej also had a surprisingly fun and approachable talk on that problem, talking about how charconv got implemented and improved in Microsoft's C++ standard library: link to this video

Kaznovon Stack Overflow • Mentions

On “Locale-independent "atof"?”

…ing (and formatting). They are located in header <charconv> . You can read more about them here: https://en.cppreference.com/w/cpp/utility/from_chars https://en.cppreference.com/w/cpp/utility/to_chars I recomment Stephan T. Lavavej wonderful talk about these two tools, here's the link to the part where he talks about using std::from_chars: link to this video And a short example by me: #include <charconv> #include <iostream> #include <system_error> int main() { char buffer16 { "123.45678" }; float result; auto p, ec = std::from_chars(std::begin(buffer), std::end(buffer), result); if(ec == std::errc{}) std::cout << result; } Unfortunately, as for today (05.06.2020) only MSVC suppo…
7View the answer

ygraon Hacker News • Mentions

On “Floating Point in the Browser, Part 1: Impossible Expectations”

Actually, there's even more recent research into doing this really efficiently, using an algorithm called Ryū. e link -4 link 1.73 link to this video

StephanTLavavejon Hacker News • Mentions

On “C++20, How Hard Could It Be”

…link CppCon 2014: STL Features And Implementation Techniques: link CppCon 2015: functional: What's New, And Proper Usage: link CppCon 2016: tuple: What's New, And How It Works: link CppCon 2018: Class Template Argument Deduction for Everyone: link CppCon 2019: Floating-Point charconv: Making Your Code 10x Faster With C++17's Final Boss: link to this video CppCon 2020: C++20 STL Features: 1 Year of Development on GitHub: link Pure Virtual C++ 2022: MSVC C++20/23 Update: link…