Single.IsNegativeInfinity() Method in C# with Examples

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

Syntax: public static bool IsNegativeInfinity (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 negative infinity, otherwise return False.



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

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to illustrate the
// Single.IsNegativeInfinity(Single)
// Method
using System;
  
class GFG {
  
    // Main method
    static public void Main()
    {
  
        // Dividing a negative number by zero
        // results in Negative infinity.
  
        // Dividing a number directly by 0
        // produces an error
        // So 0 is stored in a variable first
  
        float zero = 0.0f;
        float value = -5f;
        float result = value / zero;
  
        // Printing result
        Console.WriteLine(result);
  
        // Check result using IsNegativeInfinity() Method
        Console.WriteLine(Single.IsNegativeInfinity(result));
  
        // Result of floating point operation
        // that is less than Single.MinValue
        // is Negative Infinity
  
        result = Single.MinValue * 7.9f;
  
        // Printing result
        Console.WriteLine(result);
  
        // Check result using IsNegativeInfinity() Method
        Console.WriteLine(Single.IsNegativeInfinity(result));
    }
}

chevron_right


Output:

-Infinity
True
-Infinity
True

Note:

  • The result of any floating point operation that is less than Single.MinValue is considered as Negative Infinity.
  • Floating-point operation return PositiveInfinity or NegativeInfinity to indicate the overflow condition.

Reference:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.