Single.IsFinite()方法用於檢查float值是否超出範圍。
用法: public static bool IsFinite (float value);
返回值:如果值是有限的,則此方法返回true,否則返回false。
以下示例程序旨在說明Single.IsFinite()方法的使用:
示例1:
// C# program to demonstrate the
// Single.IsFinite() Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing value1
float value1 = 1654.268416f;
// using IsFinite() method
bool value = Single.IsFinite(value1);
// Displaying the result
if (value)
Console.WriteLine("{0} is finite", value1);
else
Console.WriteLine("{0} is not finite", value1);
}
}
輸出:
1654.268 is finite
示例2:
// C# program to demonstrate the
// Single.IsFinite() Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing value1
float value1 = (float)Math.Pow(2, 10000000);
// using IsFinite() method
bool value = Single.IsFinite(value1);
// Displaying the result
if (value)
Console.WriteLine("{0} is finite", value1);
else
Console.WriteLine("{0} is not finite", value1);
}
}
輸出:
Infinity is not finite
參考:
相關用法
- C# MathF.Tan()用法及代碼示例
- C# MathF.Abs()用法及代碼示例
- C# MathF.Max()用法及代碼示例
- C# MathF.Log()用法及代碼示例
- C# MathF.Min()用法及代碼示例
- C# MathF.Cos()用法及代碼示例
- C# MathF.Exp()用法及代碼示例
- C# MathF.Pow()用法及代碼示例
- C# MathF.Sin()用法及代碼示例
- C# UInt16.GetHashCode用法及代碼示例
- C# Single.IsNegative()用法及代碼示例
- C# Single.CompareTo()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 Single.IsFinite() Method in C# with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。