Hello, and welcome back.
In this lecture, I want to talk about some of the math functions that are
provided by the standard c library.
So to use common math functions, you have to include
the math.h header file.
And you also have to link to the math library.
The linking usually happens for you when you build using
an IDE like code blocks.
But the math functions are great for performing arithmetic and
specific complicated arithmetic.
So there's a lot of different functions.
I'm just going to describe some of the main ones.
You'll have to look at the header file in detail to see other things.
But to start off, there's cosine functions.
So in this case a cosine h.
This is the hyperbolic arccosine. So if your math was out there
you know what this means.
Asin returns the arcsine.
They all take usually integer values and return doubles.
Atangent returns the arctangent.
But again, you should notice that these are functions that
you wouldn't be able figure out.
Well, you could figure out, but it'd be really hard to if
you were to perform a number of different statements in arithmetic.
We have our arithmetic operators plus minus star multiplication,
division and mod, but these are specific functions that do
a lot of nice things for you.
Ceil, that will return the smallest energy value
greater than or equal to x.
If you have a floating point number, it will convert it
to like the ceiling of it.
Other ones, cosine returns the cosine of r.
Floor, this will return the largest integer value,
less than or equal to x.
So this value is returned as a double.
The best way to learn these functions is to use them inside your IDE.
Play around, create some integers, pass them in see what's returned.
Log.
Log is the logarithm function.
It turns a double.
Nan is not a number.
This returns a nan if possible according to the content specified
by the string, so this gets passed a string and it will tell you
whether or not this is a number.
So if you passed in something like Jason, it would return nan.
It wasn't something like Jason, like a number, it wouldn't return,
it would say it was a number.
Pow.
This is the power function.
When you raise something to the power, so 3 squared
3, 3, 3 cubed and so forth.
This is very useful, used more than having to come up with
your own power implementation.
Remainder.
You could use this as opposed to the mod operator, the modulus
operator which is the percent symbol.
Other functions, round.
This will round a number to the nearest integer
in floating point format.
Halfway values are always rounded away from zero.
So 0.5 would be rounded to 1.0
Sin returns the sine of a number.
Square root, this will return the square root of a number.
Pretty useful.
It turns a double in case you can't find the square root.
Tangent will return the tangent of a number.
And then there's so many more.
There's actually a complex arithmetic library that you can use
for even more complex arithmetic.
I wanted to describe you the main functions in the math
library, the ones that you tend to use quite a bit, like square
root and power and so forth.
But if you want to get more information, you can look up
the complex arithmetic library.