0Pricing
C++ Academy · Lesson

The cmath Header: pow sqrt abs round

Use the standard math library for common mathematical operations.

The <cmath> Header

Standard mathematical functions live in <cmath>. Most accept and return double; overloads for float and long double exist too.

Powers: pow

std::pow(base, exp) raises base to the power exp. Returns double.

#include <cmath>
double x = std::pow(2.0, 10);   // 1024.0
double y = std::pow(9.0, 0.5);  // 3.0

All lessons in this course

  1. Integer vs Floating Point Types
  2. The cmath Header: pow sqrt abs round
  3. Random Numbers with the random Header
  4. Numeric Limits and Overflow Behaviour
← Back to C++ Academy