Back to Top

Sunday 12 April 2015

Begginer's Guide to C++- Chapter 2.1: math.h Header File

As I indicated earlier, we are now heading into the “Perfection Phase”. I will NOT be teaching anything new, but rather I will give you some deeper insight into C++. These articles will be excessively short, and will focus more on a particular concept.

This post will be telling you about the important and the most used functions of the header file “math.h”. Below, I use x to denote a variable/expression/constant.

  1. ceil(x) - Returns the smallest integer not less than x. Eg- ceil(-4.8) gives output as -4, and ceil(5.9) gives output as 5.
  2. floor(x) - It returns the largest integer not greater than x. Eg- floor(100.12) gives output as 100.
  3. fabs(x) - It returns the absolute value/modulus of x. Eg- fabs(-45.1) gives output as 45.1, while fabs(100.12) gives output as 100.12. It necessarily converts a negative number to a positive one.
  4. exp(x) - Finds the value of ex.
  5. log(x)- Finds the value of logex.
  6. log10(x)- Finds the value of log10x.
  7. pow(x,y)- It returns the value of xy. Eg pow(2,3) will give output as 8.
  8. sqrt(x)- Finds the value of x0.5. Essentially finds the value of square root of x.

This was all I could come up with after yesterday's exhaustion. It was a very busy day indeed, but the next post will be much sooner.

We recently changed our logo. Do you like it? Please comment, it really took some time to make, and I would be happy is you all take out since some to tell me how you feel about it!