📜  C#中的MathF.Log10()方法与示例

📅  最后修改于: 2021-05-29 13:31:37             🧑  作者: Mango

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

语法: public static float Log10(float x);
在此, x是要计算其对数的指定数字,其类型为System.Single

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

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

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

例子:

// 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));
    }
}
输出:
0.9950646
-Infinity
NaN
NaN
Infinity
NaN