Open In App

MathF.Log10() Method in C# with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

In C#, MathF.Log10(Single) is a MathF class method. It is used to return the base 10 logarithm of a specified number.

Syntax: public static float Log10 (float x);
Here, x is the specified number whose logarithm to be calculated and its type is System.Single.

Return Value: It returns the logarithm of val(base 10 log of val) and its type is System.Single.

Note: Parameter x is always specified as a base 10 number. The return value is depend on the argument passed. Below are some cases:

  • If the argument is positive then method will return the natural logarithm or log10(val).
  • If the argument is zero, then the result is NegativeInfinity.
  • If the argument is Negative(less than zero) or equal to NaN, then the result is NaN.
  • If the argument is PositiveInfinity, then the result is PositiveInfinity.
  • If the argument is NegativeInfinity, then the result is NaN.

Example:




// C# program to demonstrate working
// of MathF.Log10(Single) method
using System;
  
class Geeks {
  
    // Main Method
    public static void Main(String[] args)
    {
  
        // float values whose logarithm
        // to be calculated
        float a = 9.887f;
        float b = 0f;
        float c = -4.45f;
        float nan = Single.NaN;
        float positiveInfinity = Single.PositiveInfinity;
        float negativeInfinity = Single.NegativeInfinity;
  
        // Input is positive number so output
        // will be logarithm of number
        Console.WriteLine(MathF.Log10(a));
  
        // positive zero as argument, so output
        // will be -Infinity
        Console.WriteLine(MathF.Log10(b));
  
        // Input is negative number so output
        // will be NaN
        Console.WriteLine(MathF.Log10(c));
  
        // Input is NaN so output
        // will be NaN
        Console.WriteLine(MathF.Log10(nan));
  
        // Input is PositiveInfinity so output
        // will be Infinity
        Console.WriteLine(MathF.Log10(positiveInfinity));
  
        // Input is NegativeInfinity so output
        // will be NaN
        Console.WriteLine(MathF.Log10(negativeInfinity));
    }
}


Output:

0.9950646
-Infinity
NaN
NaN
Infinity
NaN


Last Updated : 04 Apr, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads