Related Articles

Related Articles

Single.IsPositiveInfinity() Method in C# with Examples
  • Last Updated : 01 May, 2019

In C#, Single.IsPositiveInfinity(Single) is a Single struct method. This method is used to check whether a specified floating-point value evaluates to positive infinity or not. In some floating point operation, it is possible to obtain a result that is positive infinity. For Example: If any positive value is divided by zero, it results in positive infinity.

Syntax: public static bool IsPositiveInfinity (float f);

Parameter:
f: It is a single-precision floating-point number of type System.Single.

Return Type: This function return a Boolean value True, if specified value evaluates to positive infinity, otherwise return False.

Example: To demonstrate the Single.IsPositiveInfinity(Single) Method



filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to illustrate the
// Single.IsPositiveInfinity(Single)
// Method
using System;
  
class GFG {
  
    // Main method
    static public void Main()
    {
  
        // Dividing a Positive number by zero
        // results in positive infinity.
  
        // Dividing a number directly by 0
        // produces an error
        // So 0 is stored in a variable first
  
        float zero = 0.0f;
        float value = 10.0f;
        float result = value / zero;
  
        // Printing result
        Console.WriteLine(result);
  
        // Check result using IsPositiveInfinity() Method
        Console.WriteLine(Single.IsPositiveInfinity(result));
  
        // Floating point operation that exceeds
        // Single.MaxValue is Positive Infinity
        result = (1.402823E+38f + ((float)9.985e307));
  
        // Printing result
        Console.WriteLine(result);
  
        // Check result using IsPositiveInfinity() Method
        Console.WriteLine(Single.IsPositiveInfinity(result));
    }
}

chevron_right


Output:

Infinity
True
Infinity
True

Note: Floating-point operation return PositiveInfinity to indicate an overflow condition.

Reference:




My Personal Notes arrow_drop_up
Recommended Articles
Page :