New Mathematical Functions
With C++17 we get lots of new mathematical functions like gcd, lcm, clamp and other special ones.
We'll cover the following...
Press + to interact
#include <iostream>#include <numeric> // for gcm, lcmint main() {std::cout << std::gcd(24, 60) << ',';std::cout << std::lcm(15, 50) << '\n';}
Press + to interact
#include <iostream>#include <algorithm> // clampint main() {std::cout << std::clamp(300, 0, 255) << ',';std::cout << std::clamp(-10, 0, 255) << '\n';}
And what’s more, here are newly available special functions, defined in the <cmath>
header.
Function | Description |
---|---|