Math Class (System) - Microsoft Docs
Math Class (System) - Microsoft Docs
Namespace: System
Assemblies: System.Runtime.Extensions.dll, mscorlib.dll, netstandard.dll
Provides constants and static methods for trigonometric, logarithmic, and other
common mathematical functions.
In this article
Definition
Examples
Fields
Methods
Applies to
C# = Copy
Examples
The following example uses several mathematical and trigonometric functions from the
Math class to calculate the inner angles of a trapezoid.
C# = Copy
/// <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);
}
Fields
E Represents the natural logarithmic base, specified by the constant, e .
Methods
Abs(Decimal) Returns the absolute value of a Decimal number.
Atan2(Double, Double) Returns the angle whose tangent is the quotient of two specified
numbers.
Ceiling(Decimal) Returns the smallest integral value that is greater than or equal to the
specified decimal number.
Ceiling(Double) Returns the smallest integral value that is greater than or equal to the
specified double-precision floating-point number.
DivRem(Int32, Int32, Calculates the quotient of two 32-bit signed integers and also returns
Int32) the remainder in an output parameter.
DivRem(Int64, Int64, Calculates the quotient of two 64-bit signed integers and also returns
Int64) the remainder in an output parameter.
Floor(Decimal) Returns the largest integral value less than or equal to the specified
decimal number.
Floor(Double) Returns the largest integral value less than or equal to the specified
double-precision floating-point number.
Round(Decimal) Rounds a decimal value to the nearest integral value, and rounds
midpoint values to the nearest even number.
Round(Decimal, Int32) Rounds a decimal value to a specified number of fractional digits, and
rounds midpoint values to the nearest even number.
Round(Decimal, Int32, Rounds a decimal value to a specified number of fractional digits, and
MidpointRounding) uses the specified rounding convention for midpoint values.
Round(Decimal, Midpoint Rounds a decimal value to the nearest integer, and uses the specified
Rounding) rounding convention for midpoint values.
Sign(Int16) Returns an integer that indicates the sign of a 16-bit signed integer.
Sign(Int32) Returns an integer that indicates the sign of a 32-bit signed integer.
Sign(Int64) Returns an integer that indicates the sign of a 64-bit signed integer.
Sign(SByte) Returns an integer that indicates the sign of an 8-bit signed integer.
Applies to
.NET Core
3.0, 2.2, 2.1, 2.0, 1.1, 1.0
.NET Framework
4.8, 4.7.2, 4.7.1, 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, 4.5.1, 4.5, 4.0, 3.5, 3.0, 2.0, 1.1
.NET Standard
2.1, 2.0, 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0
UWP
10.0
Xamarin.Android
7.1
Xamarin.iOS
10.8
Xamarin.Mac
3.0
Yes No