📜  C#| Math.Log10()方法

📅  最后修改于: 2021-05-30 01:04:40             🧑  作者: Mango

在C#中, Math.Log10()是Math类方法。它用于返回指定数字的以10为底的对数。

句法:

public static double Log10(double val)

范围:

返回值:它返回val的对数(底数10日志val的)和它的类型是System.Double。

注意:参数val始终指定为以10为底的数字。返回值取决于传递的参数。以下是一些情况:

  • 如果参数为正,则method将返回自然对数或log 10 (val)
  • 如果参数为零,则结果为NegativeInfinity
  • 如果参数为Negative(小于零)或等于NaN ,则结果为NaN
  • 如果参数为PositiveInfinity ,则结果为PositiveInfinity
  • 如果参数为NegativeInfinity ,则结果为NaN

例子:

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

参考: https://msdn.microsoft.com/zh-cn/library/system.math.log10(v=vs.110).aspx