Single.IsInfinity() Method in C# with Example
Last Updated :
11 Apr, 2022
In C#, Single.IsInfinity(Single) is a Single struct method. This method is used to check whether a specified floating-point value evaluates to either positive infinity or negative infinity or not. While performing some mathematical operations, it is possible to obtain a result that is either positive infinity or negative infinity. For Example: If any positive value is divided by zero, it results in positive infinity.
Syntax: public static bool IsInfinity (float f); Parameter: <emf: It is a single-precision floating-point number of type System.Single.
Return Type: This method return a boolean value True, if the specified value evaluates to either positive infinity or negative infinity, otherwise return False. Example:
CSHARP
using System;
class GFG {
static public void Main()
{
float zero = 0.0f;
float value = 10.0f;
float result = value / zero;
Console.WriteLine(result);
Console.WriteLine(Single.IsInfinity(result));
result = Single.MaxValue * 9.25f;
Console.WriteLine(result);
Console.WriteLine(Single.IsInfinity(result));
result = Single.MinValue * 9.565f;
Console.WriteLine(result);
Console.WriteLine(Single.IsInfinity(result));
}
}
|
Output:
Infinity
True
Infinity
True
-Infinity
True
Note: Floating-point operations return PositiveInfinity or NegativeInfinity to signal an overflow condition. Reference:
Share your thoughts in the comments
Please Login to comment...