math.h library

To help us solve mathematical functions, we can use a variety of libraries, depending on our goals. The main library is  math.h  (https://cppreference.com/w/c/header/math.html).

If we also want to include math with complex numbers, we can use  complex.h  and/or  tgmath.h  libraries.

Notice the following

  • When compiling the program, we must specify an additional build argument (-lm) to the compiler.  This links the mathematics library to our program.
  • Math functions typically return their result. If you want to use the result later on, you need to store the result in a variable. If however you only need it as a part of a larger equation, you can  use it in-place without separately storing the result.
  • To get n-th root, we can use the properties of power. Make sure to use floats for the division (e.g. 1.0 instead of 1). This is necessary due to integer division truncating the decimal places.