Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c#
double
infinity
communitycreator

What is Double.IsNegativeInfinity() in C#?`

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The Double.IsNegativeInfinity() method in C# is checks if a specified number evaluates to negative infinity.

Syntax

public static bool IsNegativeInfinity (double d);
Syntax for Checking If a Number is Negative Infintiy

Parameters

d: This is the value we check for negative infinity.

Return value

A boolean value is returned. true is returned if d evaluates to negative infinity. Otherwise, false is returned.

Code example

// use System
using System;
// create class
class ValueIsInfinity
{
// main method
static void Main()
{
// create some values
double d1 = -5.0 / 0;
double d2 = 0.0 / 0.0;
double d3 = 1.0 / 1.0;
double d4 = -3.4 / 0.0;
// call the IsNegativeInfinity() method
bool b1 = Double.IsNegativeInfinity(d1);
bool b2 = Double.IsNegativeInfinity(d2);
bool b3 = Double.IsNegativeInfinity(d3);
bool b4 = Double.IsNegativeInfinity(d4);
// Printe results
Console.WriteLine(b1);
Console.WriteLine(b2);
Console.WriteLine(b3);
Console.WriteLine(b4);
}
}
Check if some number values are negative infinity

Explanation

  • Line 10 - 13: We create some double variables d1, d2 , d3 and d4. Then, we initialize them with some values.
  • Lines 16-19: We check if the variables we create are negative infinity using the Double.IsNegativeInfinty() method. Then, we store the results in Boolean variables b1,b2,b3, and b4.
  • Lines 22-25: We print the results.

RELATED TAGS

c#
double
infinity
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring