Double.IsNegativeInfinity() Method in C#

In C#, Double.IsNegativeInfinity() is a Double struct method. This method is used to check whether a specified 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 (double d);
Parameter:
d: It is a double-precision floating-point number of type System.Double.

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



Example:

Input  : d = -5.0 / 0.0 
Output : True

Input  : d = -1.5935e250 * 7.948e110
Output : True

Code: To demonstrate the Double.IsNegativeInfinity(Double) Method

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

-Infinity
True
-Infinity
True

Note:

  • The result of any floating point operation that is less than Double.MinValue (i.e -1.7976931348623157E+308 ) is considered as Negative Infinity.
  • Floating-point operation return Infinity (Positive Infinity) or -Infinity (Negative Infinity) to indicate an overflow condition.


My Personal Notes arrow_drop_up

self motivated and passionate programmer

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.