Why does Stroustrup define a sqrt function in the "C ++ 3rd Edition Programming Program (online)"?

Bjarne Stroustrup, in the 3rd edition ( online ) of his book "C ++ Programming Language", chapter 2, p. 23 (pdf p. 34), defines the sqrt function in the fragment paradigm. Why doesn't he just use one that is already included in the standard library?

+5
source share
2 answers

Because sqrt is an example of a "good style" procedural function. It takes input, processes it, and returns the result.

The book does not say that you should write your own or copy the definition from the book (which is not fully implemented in any case). The book also does not show how to calculate the square root. It describes the purpose of functions in procedural programming (or what my interpretation is anyway).

+7
source

And just in case, when you plan to write your own sqrt (), look at some source code, for example, the first one I found on Google:

https://opensource.apple.com/source/Libm/Libm-92/ppc.subproj/sqrt.c

ACCU October 2016 Overload magazine has an article entitled β€œEight Routine Pieces”

https://accu.org/index.php/journals/2294

The bogosqrt () solution, which I found particularly funny.

0
source

Source: https://habr.com/ru/post/1263775/


All Articles