Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
I don't get an error when dividing by zero
Message
De
15/01/2005 16:20:34
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
00977502
Message ID:
00977504
Vues:
28
This message has been marked as the solution to the initial question of the thread.
What's interesting about this, Zakaria, is that if you were to use an integer instead of a double, you *would* get the DivideByZeroException.

So, since you obviously need to use double, it looks like you'll have to do the checking for zero yourself. Incidentally, that should be the preferred way of doing it anyway. Relying on an exception to catch this sort of thing is waaaaay slower than executing the if statement (of course, if you seldom run into the zero situation, then it probably ends up being slower checking every case for zero <g>).

~~Bonnie



>Hello All,
>
>I have a table with a column named Qx, this column is calculated for every row with the use of two other columns as below :
>
>
>
>double Lx = (double)TableLx.Rows[i][cMortTable]
>double Lx1 = (double)TableLx.Rows[this.Min_Max(i + 1)][cMortTable];
>
>MyTable.Rows[i]["Qx"] = (Lx - Lx1) / Lx;
>
>
>For some rows Lx become zero but to my surprise I don't get an error or exception fault. When I view MyTable the rows are filled with nAn.
>
>What is the logic behind this? I wanted to catch an exception (dividedbyzero or something like that) so when it is divided by zero I can replace the rows by zero instead of nan. I know I could go around this by adding a if statement....but I just don't understand why the code doesn't generate an error.javascript:MessageSubmit()
>
>
>Thank you.
>
>Zakaria al Azhar
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform