Math functions in C#

王林
Release: 2023-09-02 17:49:07
forward
1328 people have browsed it

C# 中的数学函数

The System.Math class in C# provides methods and properties that perform mathematical operations, trigonometric, logarithmic calculations, etc.

Some of its methods include-

5
Sr.No Methods and Instructions
1 Abs(Decimal)

Returns the absolute number of Decimal.

2 Abs (Double)

Returns the absolute value of a double precision floating point number.

3 Abs(Int16)

Returns the absolute value of a 16-bit signed integer .

4 Abs(Int32)

Returns the absolute value of a 32-bit signed integer .

Abs(Int64)

Returns the absolute value of a 64-bit signed integer .

6 Abs(SByte)

Returns the absolute value of an 8-bit signed integer .

7 #Abs(Single)

Returns an absolute single-precision floating point number.

8 Acos(Double)

Returns the angle whose cosine is the specified number.

9 #Asin (double precision)

Returns the angle whose sine value is the specified number .

10 Atan(Double)

Returns the angle whose tangent value is the specified number.

Please refer to MSDN for all methods

Let us see an example of getting the absolute value-

Example

using System;

class Program {
   static void Main() {
      int val1 = 250;
      int val2 = -150;

      Console.WriteLine("Before...");
      Console.WriteLine(val1);
      Console.WriteLine(val2);

      int abs1 = Math.Abs(val1);
      int abs2 = Math.Abs(val2);

      Console.WriteLine("After...");
      Console.WriteLine(abs1);
      Console.WriteLine(abs2);
   }
}
Copy after login

Logarithmic and trigonometric functions are also part of the system. Trigonometric functions like ACos, ASin, Sin, Cos, Tan, etc. are included in the Math class in C#. It belongs to the Math type of the System namespace.

The following is an example showing how to implement trigonometric functions in C#:

Example

using System;

class Program {
   static void Main() {
      Console.WriteLine(Math.Acos(0));
      Console.WriteLine(Math.Cos(2));

      Console.WriteLine(Math.Asin(0.2));
      Console.WriteLine(Math.Sin(2));
   }
}
Copy after login

The above is the detailed content of Math functions in C#. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template