- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Math.Log() Method in C#
The Math.Log() method in C# is used to return the logarithm of a specified number.
Syntax
public static double Log(double num) public static double Log(double num, double base)
Above, num is the specified number whose logarithm is to be calculated. Here, the base is the base of the logarithm.
Let us now see an example to implement the Math.Log() method −
Example
using System; public class Demo { public static void Main(){ double val1 = 2.15; double val2 = -2.15; Console.WriteLine(Math.Log(val1)); Console.WriteLine(Math.Log(val2)); } }
Output
This will produce the following output −
0.765467842139571 NaN
Example
Let us see another example to implement the Math.Log() method −
using System; public class Demo { public static void Main(){ double val1 = Double.PositiveInfinity; ; double val2 = Double.NegativeInfinity; Console.WriteLine(Math.Log(val1)); Console.WriteLine(Math.Log(val2)); } }
Output
This will produce the following output −
∞ NaN
Advertisements