
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Mathematical Functions in C#
The System.Math class in C# provides methods are properties to perform mathematical operations, trigonometric, logarithmic calculations, etc.
Some of its methods include −
Sr.No | Method & Description |
---|---|
1 | Abs(Decimal) Returns the absolute value of a Decimal number. |
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. |
5 | 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 the absolute value of a single-precision floating-point number. |
8 | Acos(Double) Returns the angle whose cosine is the specified number. |
9 | Asin(Double) Returns the angle whose sine is the specified number. |
10 | Atan(Double) Returns the angle whose tangent is the specified number. |
For all the methods, refer MSDN
Let us see an example to get 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); } }
Logarithmic and Trigonometric functions are also part of the System. Math class in C#. Trigonometric Functions in C# includes ACos, ASin, Sin, Cos, Tan, etc. It comes under 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)); } }
- Related Articles
- Mathematical Functions in Python?
- Mathematical Functions in Java
- Mathematical Functions in SQL
- Python Mathematical Functions
- C++ Mathematical Functions
- Mathematical statistics functions in Python
- Mathematical Functions in Python - Special Functions and Constants
- Mathematical Functions using Python
- Program to evaluate one mathematical expression without built-in functions in python
- Mathematical Constants in Python
- HTML5 Mathematical operators
- Mathematical Logical Connectives
- Mathematical Foundation Introduction
- PHP Predefined Mathematical Constants
- Removing parentheses from mathematical expressions in JavaScript

Advertisements