?????? ???????????????? ?????????????? ???? ????????. ???? ????? Here is some C++ code that prints ?????????? 1 / 3 ??????????: ???????????? ?? = ??.0 / ??.0; ??????::??????????????("{}", ??); ?????????? ?? = ??.0 / ??.0; ??????::??????????????("{}", ??); It prints 0.???????????????????????????????? and 0.???????????????? [2]. ?? Are you surprised that digit 4 appeared? Do you think this is a C++ bug? ???? Actually, this is by design and also happens in C# [3], Go [4], Java [5], Rust [6] and certainly many other programming languages. ?? If you are curious and want to know what's going on, then watch my talk at CppCon, The C++ Conference, "?? ?????? ???????????? ???? ?????? ??????: ???????? ???????????????????? ???????? ????????????????-?????????? ??????????????." The talk [1] is not specific to C++ and is accessible to programmers of other languages. ?? What do dragons have to do with printing floating-point numbers? Watch the talk [1] to find out. ?? "?????????????????? ???????? ???????? ?????? ???????????? ?????? ???????? ???????????? ???????? ????????" -- @WndSks ?? "???????????? ?????????????????????? ?????? ?????? ???????? ???????? ????????????????" -- @christer8964 Please click on like ??, share this post and follow me. References. [1] https://lnkd.in/etevqtYR [2] https://lnkd.in/etRtV-d6 [3] https://lnkd.in/eYFVN_WE [4] https://lnkd.in/e_TBHZdf [5] https://lnkd.in/eKwAdYe6 [6] https://lnkd.in/eadRY5tE #mathematics #algorithms #programming #floatingpoint
CppCon, The C++ Conference 2024 - Cassio Neri: "How to Quickly Convert Floating-Point Numbers in C++" youtu.be/fPZ1ZdA7Iwc Standard C++ provides a few functions to convert a double or float value to string, namely, sprintf, stringstream::operator<<, snprintf, to_string, to_chars and format. This talk concerns what goes on behind the scenes, i.e, the algorithms which these functions might use to do their job. Curiously, many of these algorithms have dragon-related names like Dragon, Grisu, Errol, Ryu and Dragonbox. Here mythology meets technology and we shall introduce the new dragon that has just arrived in the den. (Please leave your bows and arrows at home, they won't be necessary here.) The following topics are some of those covered in this presentation:- algorithms, mathematics, arithmetic, floating point, floating point numbers, floating point math, floating point arithmetic, decimal floating-point representation, binary floating-point representation, IEEE 754, programming languages, c++, cpp --- Cassio Neri holds a PHD in Applied Mathematics from University of Paris Dauphine. Cassio has been professionally coding in C++ for more than 15 years but his coding experience has started far earlier when he was a kid. He currently works on the financial industry in London but had previously worked in academia for more than a decade. Cassio authored research articles and has published them on peer-reviewed journals on Mathematics, Finance, Computer Science and C++.