Curiosity, learning and homework help
19/04/2024
Sign upLog in
Language: FR | ENG

NEWSLETTER

:

MEMBERS

Come to discuss on the forum!
 FAST and FREE signup. 
😀 Access to discussion forums 😀
Help for HOMEWORKS, support in COMPUTER SCIENCE, help for learning FRENCH and ENGLISH, discussion on your INTERESTS and HOBBIES...

Following numerous requests, a new forum on PIPENET Vision has been created!

Some mathematical functions in C#
In C# ("C sharp"), to be able to use mathematical functions, you need to import the Math class that comes with the C# System namespace. So you must not forget to add the following line:
using System;

Then, all mathematical functions from the Math class become accessible.

    Example :
      using System;

      double x = Math.Cos(Math.PI);
      Console.WriteLine(x);

      This succession of instructions returns the value of \(cos(\pi)\), namely -1.

Here is a non-exhaustive list of the functions available in the C# Math class:

  • To calculate the logarithm of a number (natural logarithm to base \(e\)): \(\ln(x)\)
  • Math.Log(x)

  • To calculate the exponential of a number: \(e^x\) (ou \(\exp(x)\))
  • Math.Exp(x)

  • To calculate the square root of a number: \(\sqrt{x}\)
  • Math.Sqrt(x)

  • To calculate the cosine of a number: \(\cos(x)\)
  • Math.Cos(x)

  • To calculate the sine of a number: \(\sin(x)\)
  • Math.Sin(x)

  • To calculate the tangent of a number: \(tan(x)\)
  • Math.Tan(x)

  • To use the number pi: \(\pi\)
  • Math.PI

  • To calculate the power of a number: \(x^y\)
  • Math.Pow(x,y)

  • To get the closest integer smaller than a number (the integral part): the greatest integer less than or equal to x
  • Math.Floor(x)

  • To get the closest integer greater than a number: the smallest integer greater than or equal to x
  • Math.Ceiling(x)

  • To calculate the absolute value of a number: \(\lvert x \rvert\)
  • Math.Abs(x)

If you have any comments or questions about the Math class of C#, you can discuss them in the forum: Discussion forums.
Share this page on social media:
Quick comments
• Scr@b [08/08/2021 at 00:48:39]
Thank you for this list!
It helped me when I needed it. 🙂

• Message from Admin:
Glad this is helpful. 😉
If you have any questions about it, please go straight to the forum!

Use of cookies on this website:
- If you are not a member of this website, no cookie is intentionally stored on your computer.
- If you are a member of this website, cookies are only used to keep your connection after each visit. This option can be deactivated at will in your profile and is deactivated by default.
- No other information is stored or retrieved without your knowledge, neither your personal information nor any other whatsoever. If in doubt, do not hesitate to contact the administrator of this website .
- Even this information banner does not use cookies and will therefore be displayed constantly on each visit on all pages of the website.