Questions tagged [divide-by-zero]

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

In computing, a program error may result from an attempt to divide by zero. Depending on the programming environment and the type of number (e.g. floating point, integer) being divided by zero, it may generate positive or negative infinity by the IEEE 754 floating point standard, generate an exception, generate an error message, cause the program to terminate, or result in a special NaN (not a number) value.

See also:

540 questions
10
votes
2 answers

Division by zero not causing runtime exception on Nvidia Jetson

I'm not very familiar with the internal details of ARM processors, but I do not understand the following behaviour on my Nvidia Jetson Nano dev board. C code sample ... //main.c #include int main() { int fred = 123; int i; …
user5069935
10
votes
1 answer

Redshift Divide By Zero Puzzler

I was getting a divide by 0 error with this code: CASE WHEN DENOMINATOR >= 0 THEN SUM(INT1 * INT2 / DENOMINATOR) ELSE 0 END AS RATIO However when I changed to the following code, it worked. CASE WHEN DENOMINATOR >= 0 THEN SUM(INT1) * INT2 /…
cjremley
  • 111
  • 1
  • 1
  • 7
10
votes
2 answers

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 error "Divide by zero error encountered." like me in this request is to avoid? update: this helped, but I do not like the decision: ads =…
Mediator
  • 14,951
  • 35
  • 113
  • 191
9
votes
4 answers

Why doesn't this windowed expression result in a divide by zero error?

I came across this answer on Programming Puzzles & Code Golf. In it, the author uses the expression (though the answer has since been edited to use a different solution): row_number()over(order by 1/0) I would have expected the 1/0 to result in a…
HoneyBadger
  • 14,750
  • 3
  • 34
  • 48
9
votes
3 answers

Handling division by zero in Pandas calculations

I have the following data: a = pd.Series([1, 2, 3]) b = pd.Series([0, 0, 0]) If there is a division by zero I want to in some cases set the result to one of the series set the result to a specific value But the following give "unexpected"…
9
votes
2 answers

Visual C++ / Weird behavior after enabling floating-point exceptions (compiler bug ?)

I am struggling to get a reliable way to catch floating points exceptions under Visual Studio (2005 or 2008). By default, under visual studio, floating point exceptions are not caught, and they are quite hard to catch (mainly because most of them…
Pascal T.
  • 3,866
  • 4
  • 33
  • 36
9
votes
6 answers

python divide by zero encountered in log - logistic regression

I'm trying to implement a multiclass logistic regression classifier that distinguishes between k different classes. This is my code. import numpy as np from scipy.special import expit def cost(X,y,theta,regTerm): (m,n) = X.shape J =…
9
votes
3 answers

PowerShell - Why "Divide By Zero Exception" is not being Caught?

On my Machine each one of the following code snippets throws and exception instead of printing to the standard output "1" and "2" Why the exception is not being Caught? try { [int]$a = 1/0 } catch { write 1 } finally { write 2 } try { …
Oz Molaim
  • 2,016
  • 4
  • 20
  • 29
8
votes
3 answers

Floating point division by zero exception in Delphi5

My app is written in Delphi5. I am using madExcept to track down bugs. I tracked down a "Floating point dvision by zero" exception, where it shouldn't be. The code segment, where it is raised, goes as followed: val:=100*Power(1.25,c); where 'c'…
simonescu
  • 462
  • 5
  • 17
8
votes
4 answers

how to check if there is a division by zero in c

#include void function(int); int main() { int x; printf("Enter x:"); scanf("%d", &x); function(x); return 0; } void function(int x) { float fx; fx=10/x; if(10 is divided by zero)// I dont know what to put…
user244775
  • 95
  • 1
  • 1
  • 5
8
votes
3 answers

Python Divide By Zero Error

I have a Class in python, with the following attributes: self.number1 = 0 self.number2 = 0 self.divided = self.number1/self.number2 This of course throws up the zero error: ZeroDivisionError: integer division or modulo by zero The…
eamon1234
  • 1,555
  • 3
  • 19
  • 38
7
votes
3 answers

Why does the standard have to address division by zero?

I was trying to understand the differences between res1 and res2 in the code below: #include int main() { int x = 1; int y = 0; double res1 = double(x)/y; // OK: evaluates to Inf int res2 = x/y; …
user51462
  • 1,658
  • 2
  • 13
  • 41
7
votes
4 answers

Can bad stuff happen when dividing 1/a very small float?

If I want to check that positive float A is less than the inverse square of another positive float B (in C99), could something go wrong if B is very small? I could imagine checking it like if(A<1/(B*B)) But if B is small enough, would this possibly…
Jeremy Salwen
  • 8,061
  • 5
  • 50
  • 73
7
votes
1 answer

How to translate kernel's trap divide error rsp:2b6d2ea40450 to a source location?

Customer reported an error in one of our programs caused by division by zero. We have only this VLM line: kernel: myprog[16122] trap divide error rip:79dd99 rsp:2b6d2ea40450 error:0 I do not believe there is core file for that. I searched through…
Grzegorz
  • 3,207
  • 3
  • 20
  • 43
7
votes
7 answers

Divide by Zero Display Values

What is the best way (most intuitive to users) or best practice for displaying the results of a divide by 0 error when doing reporting? Within the report, I capture this error, however, when displaying it on a human readable report; I am not sure…
Irwin M. Fletcher
  • 2,606
  • 3
  • 25
  • 29