Class: Math

Namespace: System

Library: mscorlib.dll

It's an static Class: you can use the name Math like the prefix/object.

The methods:

Abs(somevalue)

Acos(somedouble)

Asin(somedouble)

Atan(somedouble)

Ceil(somedouble)

Cos(somedouble)

Exp(somedouble)

Floor(somedouble)

Log(somedouble)

Log10(somedouble)

Max(avalue, anothervalue)

Min(avalue, anothervalue)

Pow(somedouble,expoent)

Round(somedouble)

If we have a ".5" the rounding is made to the nearest even:

Example:

Sign(somevalue)

The convention for the return of this method is

 -1 : negative
 +1 : positive
  0 : if we have a zero

Sin(somedouble)

Sqrt(somedouble)

Tan(somedouble)

And there are the double Math.PI whose value is the 3.14...

In the methods (Cos, Sin etc.) the angles need to be always in radians. We can to convert. Look:

Example:

Sometimes in games we need to have a randomic number between some values (from zero to six, by example). There are the Class Random, that is not static. Look the example. Everytime you run the program you will have a different value:

Example:




PREVIOUS LESSON NEXT LESSON
T.CONTENTS HOMEPAGE