Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express mathematical infinity in C#

Is it possible to express (mathematical) infinity, positive or negative, in C#? If so, how?

like image 472
Alex Avatar asked Aug 30 '09 00:08

Alex


People also ask

How do you write infinity in C?

There is no representation of infinity in C. infinity, if available; else to a positive constant of type float that overflows at translation time.

How do you express infinity in math?

The infinity symbol ∞ is sometimes called the lemniscate and is a mathematical symbol representing the concept of infinity. The sign of infinity is used more often to represent a potential infinity, rather than to represent an actually infinite quantity such as the ordinal numbers and cardinal numbers.

How do you write infinity in C Plus Plus?

The C++ infinity is written as “INF” and it accrues in the outcome of dividing a positive numeric value by a null value or calculating a numeric value that is greater than the larger number of our system that can be represented in 64 bits.


2 Answers

Use the PositiveInfinity and NegativeInfinity constants:

double positive = double.PositiveInfinity; double negative = double.NegativeInfinity; 
like image 96
Jeff L Avatar answered Sep 23 '22 04:09

Jeff L


double.PositiveInfinity

double.NegativeInfinity

float zero = 0;  float positive = 1 / zero; Console.WriteLine(positive);    // Outputs "Infinity"  float negative = -1 / zero; Console.WriteLine(negative);    // Outputs "-Infinity" 
like image 39
Jaimal Chohan Avatar answered Sep 22 '22 04:09

Jaimal Chohan