- 1

Divisione by zero

when dividing by zero it doesn't give me an error, but the result is 8, why?

7th Nov 2017, 8:02 PM
Thrap
Thrap - avatar
7 Answers
+ 31
Show us your code.
7th Nov 2017, 8:04 PM
Igor Makarsky
Igor Makarsky - avatar
+ 5
That returns an infinity in C# which is basically an arbitrary integer in memory. You need to provide an exception to return the proper description of it. It's still practically impossible to divide by zero.
7th Nov 2017, 8:15 PM
Ray Joe
Ray Joe - avatar
+ 4
Show the code.
7th Nov 2017, 8:04 PM
Ray Joe
Ray Joe - avatar
+ 3
{ double x = Convert.ToInt16(Console.ReadLine()); double y = Convert.ToInt16(Console.ReadLine()); double z = x / y; Console.WriteLine(z); } @Igor Makarsky @M Squared
7th Nov 2017, 8:07 PM
Thrap
Thrap - avatar
+ 3
oh, ok
7th Nov 2017, 8:17 PM
Thrap
Thrap - avatar
+ 3
thanks, I'll remember it
7th Nov 2017, 8:50 PM
Thrap
Thrap - avatar
+ 2
So basically you can check a boolean to find the type of infinity here: https://code.sololearn.com/cBtiDriapHD8/#cs
7th Nov 2017, 8:20 PM
Ray Joe
Ray Joe - avatar