Is it possible to express (mathematical) infinity, positive or negative, in C#? If so, how?
There is no representation of infinity in C. infinity, if available; else to a positive constant of type float that overflows at translation time.
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.
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.
Use the PositiveInfinity
and NegativeInfinity
constants:
double positive = double.PositiveInfinity; double negative = double.NegativeInfinity;
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With