# Math 类

## 定义

``public ref class Math abstract sealed``
``public static class Math``
``type Math = class``
``Public Class Math``

Math

## 示例

``````/// <summary>
/// The following class represents simple functionality of the trapezoid.
/// </summary>
using namespace System;

public ref class MathTrapezoidSample
{
private:
double m_longBase;
double m_shortBase;
double m_leftLeg;
double m_rightLeg;

public:
MathTrapezoidSample( double longbase, double shortbase, double leftLeg, double rightLeg )
{
m_longBase = Math::Abs( longbase );
m_shortBase = Math::Abs( shortbase );
m_leftLeg = Math::Abs( leftLeg );
m_rightLeg = Math::Abs( rightLeg );
}

private:
double GetRightSmallBase()
{
return (Math::Pow( m_rightLeg, 2.0 ) - Math::Pow( m_leftLeg, 2.0 ) + Math::Pow( m_longBase, 2.0 ) + Math::Pow( m_shortBase, 2.0 ) - 2 * m_shortBase * m_longBase) / (2 * (m_longBase - m_shortBase));
}

public:
double GetHeight()
{
double x = GetRightSmallBase();
return Math::Sqrt( Math::Pow( m_rightLeg, 2.0 ) - Math::Pow( x, 2.0 ) );
}

double GetSquare()
{
return GetHeight() * m_longBase / 2.0;
}

{
double sinX = GetHeight() / m_leftLeg;
return Math::Round( Math::Asin( sinX ), 2 );
}

{
double x = GetRightSmallBase();
double cosX = (Math::Pow( m_rightLeg, 2.0 ) + Math::Pow( x, 2.0 ) - Math::Pow( GetHeight(), 2.0 )) / (2 * x * m_rightLeg);
return Math::Round( Math::Acos( cosX ), 2 );
}

double GetLeftBaseDegreeAngle()
{
double x = GetLeftBaseRadianAngle() * 180 / Math::PI;
return Math::Round( x, 2 );
}

double GetRightBaseDegreeAngle()
{
double x = GetRightBaseRadianAngle() * 180 / Math::PI;
return Math::Round( x, 2 );
}

};

int main()
{
MathTrapezoidSample^ trpz = gcnew MathTrapezoidSample( 20.0,10.0,8.0,6.0 );
Console::WriteLine( "The trapezoid's bases are 20.0 and 10.0, the trapezoid's legs are 8.0 and 6.0" );
double h = trpz->GetHeight();
Console::WriteLine( "Trapezoid height is: {0}", h.ToString() );
double dxR = trpz->GetLeftBaseRadianAngle();
Console::WriteLine( "Trapezoid left base angle is: {0} Radians", dxR.ToString() );
double dyR = trpz->GetRightBaseRadianAngle();
Console::WriteLine( "Trapezoid right base angle is: {0} Radians", dyR.ToString() );
double dxD = trpz->GetLeftBaseDegreeAngle();
Console::WriteLine( "Trapezoid left base angle is: {0} Degrees", dxD.ToString() );
double dyD = trpz->GetRightBaseDegreeAngle();
Console::WriteLine( "Trapezoid left base angle is: {0} Degrees", dyD.ToString() );
}
``````
``````/// <summary>
/// The following class represents simple functionality of the trapezoid.
/// </summary>
using System;

namespace MathClassCS
{
class MathTrapezoidSample
{
private double m_longBase;
private double m_shortBase;
private double m_leftLeg;
private double m_rightLeg;

public MathTrapezoidSample(double longbase, double shortbase, double leftLeg, double rightLeg)
{
m_longBase = Math.Abs(longbase);
m_shortBase = Math.Abs(shortbase);
m_leftLeg = Math.Abs(leftLeg);
m_rightLeg = Math.Abs(rightLeg);
}

private double GetRightSmallBase()
{
return (Math.Pow(m_rightLeg,2.0) - Math.Pow(m_leftLeg,2.0) + Math.Pow(m_longBase,2.0) + Math.Pow(m_shortBase,2.0) - 2* m_shortBase * m_longBase)/ (2*(m_longBase - m_shortBase));
}

public double GetHeight()
{
double x = GetRightSmallBase();
return Math.Sqrt(Math.Pow(m_rightLeg,2.0) - Math.Pow(x,2.0));
}

public double GetSquare()
{
return GetHeight() * m_longBase / 2.0;
}

{
double sinX = GetHeight()/m_leftLeg;
return Math.Round(Math.Asin(sinX),2);
}

{
double x = GetRightSmallBase();
double cosX = (Math.Pow(m_rightLeg,2.0) + Math.Pow(x,2.0) - Math.Pow(GetHeight(),2.0))/(2*x*m_rightLeg);
return Math.Round(Math.Acos(cosX),2);
}

public double GetLeftBaseDegreeAngle()
{
double x = GetLeftBaseRadianAngle() * 180/ Math.PI;
return Math.Round(x,2);
}

public double GetRightBaseDegreeAngle()
{
double x = GetRightBaseRadianAngle() * 180/ Math.PI;
return Math.Round(x,2);
}

static void Main(string[] args)
{
MathTrapezoidSample trpz = new MathTrapezoidSample(20.0, 10.0, 8.0, 6.0);
Console.WriteLine("The trapezoid's bases are 20.0 and 10.0, the trapezoid's legs are 8.0 and 6.0");
double h = trpz.GetHeight();
Console.WriteLine("Trapezoid height is: " + h.ToString());
double dxR = trpz.GetLeftBaseRadianAngle();
Console.WriteLine("Trapezoid left base angle is: " + dxR.ToString() + " Radians");
double dyR = trpz.GetRightBaseRadianAngle();
Console.WriteLine("Trapezoid right base angle is: " + dyR.ToString() + " Radians");
double dxD = trpz.GetLeftBaseDegreeAngle();
Console.WriteLine("Trapezoid left base angle is: " + dxD.ToString() + " Degrees");
double dyD = trpz.GetRightBaseDegreeAngle();
Console.WriteLine("Trapezoid left base angle is: " + dyD.ToString() + " Degrees");
}
}
}
``````
``````'The following class represents simple functionality of the trapezoid.
Class MathTrapezoidSample

Private m_longBase As Double
Private m_shortBase As Double
Private m_leftLeg As Double
Private m_rightLeg As Double

Public Sub New(ByVal longbase As Double, ByVal shortbase As Double, ByVal leftLeg As Double, ByVal rightLeg As Double)
m_longBase = Math.Abs(longbase)
m_shortBase = Math.Abs(shortbase)
m_leftLeg = Math.Abs(leftLeg)
m_rightLeg = Math.Abs(rightLeg)
End Sub

Private Function GetRightSmallBase() As Double
GetRightSmallBase = (Math.Pow(m_rightLeg, 2) - Math.Pow(m_leftLeg, 2) + Math.Pow(m_longBase, 2) + Math.Pow(m_shortBase, 2) - 2 * m_shortBase * m_longBase) / (2 * (m_longBase - m_shortBase))
End Function

Public Function GetHeight() As Double
Dim x As Double = GetRightSmallBase()
GetHeight = Math.Sqrt(Math.Pow(m_rightLeg, 2) - Math.Pow(x, 2))
End Function

Public Function GetSquare() As Double
GetSquare = GetHeight() * m_longBase / 2
End Function

Public Function GetLeftBaseRadianAngle() As Double
Dim sinX As Double = GetHeight() / m_leftLeg
GetLeftBaseRadianAngle = Math.Round(Math.Asin(sinX), 2)
End Function

Public Function GetRightBaseRadianAngle() As Double
Dim x As Double = GetRightSmallBase()
Dim cosX As Double = (Math.Pow(m_rightLeg, 2) + Math.Pow(x, 2) - Math.Pow(GetHeight(), 2)) / (2 * x * m_rightLeg)
GetRightBaseRadianAngle = Math.Round(Math.Acos(cosX), 2)
End Function

Public Function GetLeftBaseDegreeAngle() As Double
Dim x As Double = GetLeftBaseRadianAngle() * 180 / Math.PI
GetLeftBaseDegreeAngle = Math.Round(x, 2)
End Function

Public Function GetRightBaseDegreeAngle() As Double
Dim x As Double = GetRightBaseRadianAngle() * 180 / Math.PI
GetRightBaseDegreeAngle = Math.Round(x, 2)
End Function

Public Shared Sub Main()
Dim trpz As MathTrapezoidSample = New MathTrapezoidSample(20, 10, 8, 6)
Console.WriteLine("The trapezoid's bases are 20.0 and 10.0, the trapezoid's legs are 8.0 and 6.0")
Dim h As Double = trpz.GetHeight()
Console.WriteLine("Trapezoid height is: " + h.ToString())
Dim dxR As Double = trpz.GetLeftBaseRadianAngle()
Console.WriteLine("Trapezoid left base angle is: " + dxR.ToString() + " Radians")
Dim dyR As Double = trpz.GetRightBaseRadianAngle()
Console.WriteLine("Trapezoid right base angle is: " + dyR.ToString() + " Radians")
Dim dxD As Double = trpz.GetLeftBaseDegreeAngle()
Console.WriteLine("Trapezoid left base angle is: " + dxD.ToString() + " Degrees")
Dim dyD As Double = trpz.GetRightBaseDegreeAngle()
Console.WriteLine("Trapezoid left base angle is: " + dyD.ToString() + " Degrees")
End Sub
End Class
``````

## 字段

 表示自然对数的底，它由常数 `e` 指定。Represents the natural logarithmic base, specified by the constant, `e`. 表示圆的周长与其直径的比值，由常数 π 指定。Represents the ratio of the circumference of a circle to its diameter, specified by the constant, π.

## 方法

 返回 Decimal 数字的绝对值。Returns the absolute value of a Decimal number. 返回双精度浮点数字的绝对值。Returns the absolute value of a double-precision floating-point number. 返回 16 位有符号整数的绝对值。Returns the absolute value of a 16-bit signed integer. 返回 32 位有符号整数的绝对值。Returns the absolute value of a 32-bit signed integer. 返回 64 位有符号整数的绝对值。Returns the absolute value of a 64-bit signed integer. 返回 8 位有符号整数的绝对值。Returns the absolute value of an 8-bit signed integer. 返回单精度浮点数字的绝对值。Returns the absolute value of a single-precision floating-point number. 返回余弦值为指定数字的角度。Returns the angle whose cosine is the specified number. 返回双曲余弦值为指定数字的角度。Returns the angle whose hyperbolic cosine is the specified number. 返回正弦值为指定数字的角度。Returns the angle whose sine is the specified number. 返回双曲正弦值为指定数字的角度。Returns the angle whose hyperbolic sine is the specified number. 返回正切值为指定数字的角度。Returns the angle whose tangent is the specified number. 返回正切值为两个指定数字的商的角度。Returns the angle whose tangent is the quotient of two specified numbers. 返回双曲正切值为指定数字的角度。Returns the angle whose hyperbolic tangent is the specified number. 生成两个 32 位数字的完整乘积。Produces the full product of two 32-bit numbers. 返回小于 `x` 的下一个最小值。Returns the next smallest value that compares less than `x`. 返回大于 `x` 的下一个最大值。Returns the next largest value that compares greater than `x`. 返回指定数字的立方根。Returns the cube root of a specified number. 返回大于或等于指定的十进制数的最小整数值。Returns the smallest integral value that is greater than or equal to the specified decimal number. 返回大于或等于指定的双精度浮点数的最小整数值。Returns the smallest integral value that is greater than or equal to the specified double-precision floating-point number. 返回限制在 `min` 和 `max` 范围内（含首尾）的 `value`。Returns `value` clamped to the inclusive range of `min` and `max`. 返回限制在 `min` 和 `max` 范围内（含首尾）的 `value`。Returns `value` clamped to the inclusive range of `min` and `max`. 返回限制在 `min` 和 `max` 范围内（含首尾）的 `value`。Returns `value` clamped to the inclusive range of `min` and `max`. 返回限制在 `min` 和 `max` 范围内（含首尾）的 `value`。Returns `value` clamped to the inclusive range of `min` and `max`. 返回限制在 `min` 和 `max` 范围内（含首尾）的 `value`。Returns `value` clamped to the inclusive range of `min` and `max`. 返回限制在 `min` 和 `max` 范围内（含首尾）的 `value`。Returns `value` clamped to the inclusive range of `min` and `max`. 返回限制在 `min` 和 `max` 范围内（含首尾）的 `value`。Returns `value` clamped to the inclusive range of `min` and `max`. 返回限制在 `min` 和 `max` 范围内（含首尾）的 `value`。Returns `value` clamped to the inclusive range of `min` and `max`. 返回限制在 `min` 和 `max` 范围内（含首尾）的 `value`。Returns `value` clamped to the inclusive range of `min` and `max`. 返回限制在 `min` 和 `max` 范围内（含首尾）的 `value`。Returns `value` clamped to the inclusive range of `min` and `max`. 返回限制在 `min` 和 `max` 范围内（含首尾）的 `value`。Returns `value` clamped to the inclusive range of `min` and `max`. 返回一个值，它具有 `x` 的大小和 `y` 的符号。Returns a value with the magnitude of `x` and the sign of `y`. 返回指定角度的余弦值。Returns the cosine of the specified angle. 返回指定角度的双曲余弦值。Returns the hyperbolic cosine of the specified angle. 计算两个 32 位有符号整数的商，并通过输出参数返回余数。Calculates the quotient of two 32-bit signed integers and also returns the remainder in an output parameter. 计算两个 64 位有符号整数的商，并通过输出参数返回余数。Calculates the quotient of two 64-bit signed integers and also returns the remainder in an output parameter. 返回 `e` 的指定次幂。Returns `e` raised to the specified power. 返回小于或等于指定小数的最大整数值。Returns the largest integral value less than or equal to the specified decimal number. 返回小于或等于指定双精度浮点数的最大整数值。Returns the largest integral value less than or equal to the specified double-precision floating-point number. 返回 (x * y) + z，舍入为一个三元运算。Returns (x * y) + z, rounded as one ternary operation. 返回一指定数字被另一指定数字相除的余数。Returns the remainder resulting from the division of a specified number by another specified number. 返回指定数字以 2 为底的整数对数。Returns the base 2 integer logarithm of a specified number. 返回指定数字的自然对数（底为 `e`）。Returns the natural (base `e`) logarithm of a specified number. 返回指定数字在使用指定底时的对数。Returns the logarithm of a specified number in a specified base. 返回指定数字以 10 为底的对数。Returns the base 10 logarithm of a specified number. 返回指定数字以 2 为底的对数。Returns the base 2 logarithm of a specified number. 返回两个 8 位无符号整数中较大的一个。Returns the larger of two 8-bit unsigned integers. 返回两个十进制数中较大的一个。Returns the larger of two decimal numbers. 返回两个双精度浮点数字中较大的一个。Returns the larger of two double-precision floating-point numbers. 返回两个 16 位有符号的整数中较大的一个。Returns the larger of two 16-bit signed integers. 返回两个 32 位有符号的整数中较大的一个。Returns the larger of two 32-bit signed integers. 返回两个 64 位有符号的整数中较大的一个。Returns the larger of two 64-bit signed integers. 返回两个 8 位有符号的整数中较大的一个。Returns the larger of two 8-bit signed integers. 返回两个单精度浮点数字中较大的一个。Returns the larger of two single-precision floating-point numbers. 返回两个 16 位无符号整数中较大的一个。Returns the larger of two 16-bit unsigned integers. 返回两个 32 位无符号整数中较大的一个。Returns the larger of two 32-bit unsigned integers. 返回两个 64 位无符号整数中较大的一个。Returns the larger of two 64-bit unsigned integers. 返回两个双精度浮点数字中的较大值。Returns the larger magnitude of two double-precision floating-point numbers. 返回两个 8 位无符号整数中较小的一个。Returns the smaller of two 8-bit unsigned integers. 返回两个十进制数中较小的一个。Returns the smaller of two decimal numbers. 返回两个双精度浮点数字中较小的一个。Returns the smaller of two double-precision floating-point numbers. 返回两个 16 位有符号整数中较小的一个。Returns the smaller of two 16-bit signed integers. 返回两个 32 位有符号整数中较小的一个。Returns the smaller of two 32-bit signed integers. 返回两个 64 位有符号整数中较小的一个。Returns the smaller of two 64-bit signed integers. 返回两个 8 位有符号整数中较小的一个。Returns the smaller of two 8-bit signed integers. 返回两个单精度浮点数字中较小的一个。Returns the smaller of two single-precision floating-point numbers. 返回两个 16 位无符号整数中较小的一个。Returns the smaller of two 16-bit unsigned integers. 返回两个 32 位无符号整数中较小的一个。Returns the smaller of two 32-bit unsigned integers. 返回两个 64 位无符号整数中较小的一个。Returns the smaller of two 64-bit unsigned integers. 返回两个双精度浮点数字中的较小值。Returns the smaller magnitude of two double-precision floating-point numbers. 返回指定数字的指定次幂。Returns a specified number raised to the specified power. 将小数值舍入到最接近的整数值，并将中点值舍入到最接近的偶数。Rounds a decimal value to the nearest integral value, and rounds midpoint values to the nearest even number. 将小数值舍入到指定数量的小数位，并将中点值舍入到最接近的偶数。Rounds a decimal value to a specified number of fractional digits, and rounds midpoint values to the nearest even number. 将小数值舍入到指定数量的小数位，并为中点值使用指定的舍入规则。Rounds a decimal value to a specified number of fractional digits, and uses the specified rounding convention for midpoint values. 将小数值舍入到最接近的整数，并为中点值使用指定的舍入规则。Rounds a decimal value to the nearest integer, and uses the specified rounding convention for midpoint values. 将双精度浮点值舍入到最接近的整数值，并将中点值舍入到最接近的偶数。Rounds a double-precision floating-point value to the nearest integral value, and rounds midpoint values to the nearest even number. 将双精度浮点值舍入到指定数量的小数位，并将中点值舍入到最接近的偶数。Rounds a double-precision floating-point value to a specified number of fractional digits, and rounds midpoint values to the nearest even number. 将双精度浮点值舍入到指定数量的小数位，并为中点值使用指定的舍入规则。Rounds a double-precision floating-point value to a specified number of fractional digits, and uses the specified rounding convention for midpoint values. 将双精度浮点值舍入到最接近的整数，并为中点值使用指定的舍入约定。Rounds a double-precision floating-point value to the nearest integer, and uses the specified rounding convention for midpoint values. 返回有效计算的 x * 2^n。Returns x * 2^n computed efficiently. 返回表示十进制数符号的整数。Returns an integer that indicates the sign of a decimal number. 返回一个整数，该整数表示双精度浮点数字的符号。Returns an integer that indicates the sign of a double-precision floating-point number. 返回表示 16 位带符号整数的整数。Returns an integer that indicates the sign of a 16-bit signed integer. 返回表示 32 位带符号整数的整数。Returns an integer that indicates the sign of a 32-bit signed integer. 返回一个整数，该整数指示 64 位带符号整数的符号。Returns an integer that indicates the sign of a 64-bit signed integer. 返回一个整数，该整数指示 8 位带符号整数的符号。Returns an integer that indicates the sign of an 8-bit signed integer. 返回一个整数，该整数表示单精度浮点数字的符号。Returns an integer that indicates the sign of a single-precision floating-point number. 返回指定角度的正弦值。Returns the sine of the specified angle. 返回指定角度的双曲正弦值。Returns the hyperbolic sine of the specified angle. 返回指定数字的平方根。Returns the square root of a specified number. 返回指定角度的正切值。Returns the tangent of the specified angle. 返回指定角度的双曲正切值。Returns the hyperbolic tangent of the specified angle. 计算一个数字的整数部分。Calculates the integral part of a specified decimal number. 计算指定双精度浮点数的整数部分。Calculates the integral part of a specified double-precision floating-point number.