6.3 Math Library Functions

Some functions, such as main, are not members of a class. These functions are called global functions. We introduce various functions from the <cmath> header here to present the concept of global functions that do not belong to a particular class.

The <cmath> header provides a collection of functions that perform common mathematical calculations. For example, you can calculate the square root of 900.0 with the function call


sqrt(900.0)

This expression evaluates to 30.0. Function sqrt takes an argument of type double and returns a double result. There’s no need to create any objects before calling function sqrt. Also, all functions in the <cmath> header are global functions—therefore, each is called simply by specifying ...

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.