This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

.NET 1.1+

# .NET Math Library

The .NET framework includes a class named "Math", which provides a number of standard mathematical functions, using static methods, and mathematical values, using simple constants. This article describes all of the Math class members.

### Asin

Asin calculates the arcsine of a value. Arcsine is the inverse of sine. Sine calculates the ratio of the opposite side and the hypotenuse of a triangle, based upon an angle. Arcsine does the opposite; the arcsine of the ratio gives the angle. As with Sin, Cos and Tan, Asin accepts a double argument and returns a double.

The following sample obtains an angle based upon the lengths of the opposing side and the hypotenuse. The ratio is calculated by simple division. The result is not exactly correct due to rounding errors and because the 0.6433 radians mentioned earlier was also an approximation.

```static void Main()
{
double angle = GetAngle(4, 5);  // angle = 0.6435
}

static double GetAngle(double opposite, double hypotenuse)
{
return Math.Round(Math.Asin(opposite / hypotenuse), 4);
}```

### Acos

Acos calculates the arccosine of a number. This is the angle whose cosine is the provided value and is also known as the inverse cosine. We can use it as follows to calculate an angle from a right-angled triangle, measured in radians, from the lengths of the adjacent side and the hypotenuse.

```static void Main()
{
double angle = GetAngle(4, 5);  // angle = 0.6435
}

static double GetAngle(double adjacent, double hypotenuse)
{
}```

### Atan

Atan completes the inverse functions for sine, cosine and tangent by calculating the arctangent. This is the angle, in radians, whose tangent is the provided value. In the sample below we use it to calculate an angle of a right-angled triangle using the opposite and adjacent sides without knowing the length of the hypotenuse.

```static void Main()
{
double angle = GetAngle(3, 4);  // angle = 0.6435
}

static double GetAngle(double opposite, double adjacent)
{
}```

### Atan2

Atan2 provides a variation on the Atan method. It produces the same results but rather than pre-calculating the ratio of the opposite and adjacent sides, we supply the two parts of the ratio to the method's two parameters. This means that Atan(0.75) is equal to Atan2(3, 4).

```static void Main()
{
double angle = GetAngle(3, 4);  // angle = 0.6435
}

static double GetAngle(double opposite, double adjacent)
{
}```

### Sinh

Sinh is used to calculate the hyperbolic sine of an angle. The hyperbolic functions are used to express the relationship between the distance of a point on a hyperbola and the co-ordinate axis when plotted on a graph. The formula for hyperbolic sine is related to the exponential functions. The formula is:

`double sinh = Math.Sinh(1); // sinh = 1.1752011936438014`

### Cosh

Cosh calculates hyperbolic cosine of an angle. The formula for hyperbolic cosine is:

`double cosh = Math.Cosh(1); // cosh = 1.5430806348152437`

### Tanh

Tanh is the third of the hyperbolic functions supported by the Math class. As the name suggests, Tanh calculates the hyperbolic tangent for an angle, which is the ratio between the hyperbolic sine and hyperbolic cosine of the same angle:

By definition, the hyperbolic tangent can also be expressed using the constant e:

`double tanh = Math.Tanh(1);  // tanh = 0.76159415595576485`
7 October 2011