Top "Divide-by-zero" questions

Division by zero is the division by any value that is exactly equal to 0 -- a computation with an undefined result.

How to prevent division by zero?

ads = ads.Where(x => (x.Amount - x.Price) / (x.Amount / 100) >= filter.Persent); if x.Amount == 0 I have …

c# linq divide-by-zero
Division by zero: Undefined Behavior or Implementation Defined in C and/or C++?

Regarding division by zero, the standards say: C99 6.5.5p5 - The result of the / operator is the quotient from the …

c++ c undefined-behavior divide-by-zero
Java: Printing out an object for debugging

I would like an easy way to print out a java object, or to say it another way, serialize an …

java json tostring infinity divide-by-zero
divide by zero error

here is the code (java): class prime { public static boolean prime (int a, int b) { if (a == 0) { return false; } else …

java divide-by-zero
Is 1/0 a legal Java expression?

The following compiles fine in my Eclipse: final int j = 1/0; // compiles fine!!! // throws ArithmeticException: / by zero at run-time Java prevents …

java divide-by-zero
Why is 0 mod 0 an error?

If I type: int main() { return 0 % 0; } I get back an error: error C2124: divide or mod by zero What is …

c++ visual-c++ math modulo divide-by-zero
Ruby way: catch division by zero

I have the following method to compute an average: def compute_average(a,b,c,d,e) total = [a,b,…

ruby refactoring divide-by-zero
Divide by zero and no error?

Just threw together a simple test, not for any particular reason other than I like to try to have tests …

c# double divide-by-zero
Inconsistency in divide-by-zero behavior between different value types

Please consider the following code and comments: Console.WriteLine(1 / 0); // will not compile, error: Division by constant zero int i = 0; Console.…

c# .net vb.net .net-3.5 divide-by-zero
Can a near-zero floating value cause a divide-by-zero error?

Everybody knows you're not supposed to compare floats directly, but rather using a tolerance: float a,b; float epsilon = 1e-6…

c++ c floating-point divide-by-zero