'Dividing an int by a float that is 0
In the following code first I divide an int to a float that is a zero and get "∞" as the output then I divide an int by an int that is a zero and get an exception which is totally expected.
Could you please tell me thoroughly why do i get "∞" when I divide by zero that is a float? I am guessing this has something to do with the way a floating point number is encoded. I would like to have a technical explanation, please.
float hh = 0;
int ff = 4;
Console.WriteLine(ff/hh);
int hh1 = 0;
int ff1 = 4;
Console.WriteLine(ff1 / hh1);
Solution 1:[1]
According to the gnu libc manual:
IEEE 754 floating point numbers can represent positive or negative infinity, and NaN (not a number). These three values arise from calculations whose result is undefined or cannot be represented accurately.
When using a float it will give you a positive or a negative infinity and this is for, from my understanding, better representation. Reading the gnu libc manual will most likely be more coherent and understandable than I can be in this answer so I urge you to check it out.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Cryptizism |
