fdim()
Published Jul 20, 2021Updated Dec 21, 2022
Contribute to Docs
The fdim()
function returns the positive difference between two arguments.
Syntax
cmath
library must be added at the top of the file.
std:fdim(x, y)
If the first argument is greater than the second argument fdim()
returns the first argument minus the second argument, otherwise it returns zero.
Example
double result1;double result2;result1 = std::fdim(6, 2); // 4result2 = std::fdim(4, 8); // 0
Codebyte Example
Use fdim()
to return the positive difference between 8
and 5
:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn C++ on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn C++
Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.Beginner Friendly11 hours