C# Matematik funktioner
Math-paketet
Det finns många olika metematik funktioner eller metoder som vi säger i C#. De finns i System.Math . Nedan finns en tabell med de tillgängliga metoderna. Math-klassen är static så vi kommer åt metoderna med klassnamnet punkt metoden. Till exempel:
x=Math.Floor(x);
Matematik metoder (Engelska i tabellen)
| Mehtod | Returns | |
| Abs | Returns the absolute value of a number. | |
| Ceiling | Returns a value that is the smallest whole number greater than or equal to a given number. | |
| Exp | Returns E raised to a given power. This is the inverse of Log. | |
| Floor | Returns a value that is the largest whole number that is less than or equal to the given number. | |
| Log | Returns a value that is the logarithmic value of the given number. | |
| Max | Returns the larger of two values. | |
| Min | Returns the smaller of two values. | |
| Pow | Returns the value of a given value raised to a given power. | |
| Round | Returns a rounded value for a number. You can specify the precision of the rounded number. The number .5 would be rounded down. | |
| Sign | Returns a value indicating the sign of a value. 1 is returned for a negative number, 0 is returned for zero, and 1 is returned for a positive number. | |
| Sqrt | Returns the square root for a given value. | |
| Acos | Returns the value of an angle whose cosine is equal to a given number. | |
| Asin | Returns the value of an angle whose sine is equal to a given number. | |
| Atan | Returns the value of an angle whose tangent is equal to a given number. | |
| Atan2 | Returns the value of an angle whose tangent is equal to the quotient of two given numbers. | |
| Cos | Returns a value that is the cosine of a given angle. | |
| Cosh | Returns a value that is the hyperbolic cosine for a given angle. | |
| Sin | Returns the sine for a given angle. | |
| Sinh | Returns the hyperbolic sine for a given angle. | |
| Tan | Returns the tangent of a specified angle. | |
| Tanh | Returns the hyperbolic tangent of a given angle. |
Pi och e
I matematik-paketet finns även två konstanter:
Math.PI = 3.14159265358979323846
Math.E =
2.7182818284590452354
Källor
Skarp programmering, Jan Skansholm, Studentlitteratur 2011