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
0
votes
0 answers

PHP Division by zero, but returns 1.33

On a page where I compare questionnaires, I calculate the average for both. However, a certain line of code always ends in a division by zero no matter what numbers I input. The code:
NullError
  • 71
  • 2
  • 11
0
votes
4 answers

Python Calculator (Dividing by zero properly)

I'm very new to programming in Python and most of the answers I have searched for are more complex versions of the script than I am looking for. I have made very simplistic calculator: loop = 1 choice = 0 while loop == 1: print 'Python…
0
votes
6 answers

SQL Server - Strange Divide By Zero

I'm executing the following query: Select guiPolygonID, dbo.fn_Yval(p1X, p1Y, p2X, p2Y, 4.003318) From [vPolygonSegments] Where dbo.fn_Yval(p1X, p1Y, p2X, p2Y, 4.003318) > 0 The important parts of function fn_Yval (all params are of type…
Soldarnal
  • 7,558
  • 9
  • 47
  • 65
0
votes
0 answers

Android strange ArithmeticException : Divide by Zero

I'm getting an ArithmeticException (Divide by 0) on a few devices in my activity. This is the Stack trace I'm getting java.lang.ArithmeticException: divide by zero at com.afre.quirky.GameActivity.a(Unknown Source) at…
Vishal Afre
  • 1,013
  • 3
  • 12
  • 39
0
votes
1 answer

Should I fix the "PHP Warning: Division by zero" errors? Does it make my server slow?

What problem can happen on my server? I'm monitoring a server and that keep occurring on the log file from some web app. Nothing is show for the users, only on the log file. More than 10 erros when some user open some report pages. Does this error…
saulob
  • 615
  • 1
  • 10
  • 25
0
votes
2 answers

TDD lets me divide by zero. Is it OK?

I used TDD to develop a class that in one part looks like this class A { public: // methods, members, stuff private: std::vector vectorA; std::vector vectorB; bool isAbove(double lowerBound) { double x =…
TobiMcNamobi
  • 4,687
  • 3
  • 33
  • 52
0
votes
2 answers

Python: While loop - how do I avoid division by zero?

I am writing code for summing the Fourier Series that ranges from [-n,n]. However, I'm having trouble with it iterating when it gets to n = 0. I wrote an 'if' statement inside my while loop so it can ignore it, but it seems like it isn't. Here's my…
ShinyPebble
  • 135
  • 1
  • 1
  • 10
0
votes
2 answers

Check if dividing by zero, then printing two lines?

I am trying to write a program that will take two user input numbers and then perform calculations based off of them, but I want to use if-statements to check if it is trying to divide by zero or the output will be infinity. import…
0
votes
6 answers

SQL Server: How to handle divide by 0 cases in query

I have a query that looks like this, and which is getting a percentage: SELECT SUM(convert(decimal(3,2), CASE WHEN Status_ID = 1 AND State_ID = 14 THEN 1 ELSE 0 END))/ SUM(convert(decimal(3,2),CASE WHEN State_ID = 14 THEN 1 ELSE…
Matt
  • 23,363
  • 39
  • 111
  • 152
0
votes
3 answers

How to remove division by zero from this function?

I use this php function to convert a numeric timestamp to something like "7 days ago", but a certain timestamp returns division by zero error, I don't know how to fix the function. function timestamp_to_ago($timestamp){ if(isset($timestamp) and…
adrianTNT
  • 3,671
  • 5
  • 29
  • 35
0
votes
2 answers

Python: Informing user of divide by zero error

I'm writing a program with a number of simple operating functions. Keep in mind I'm fairly new to this. As you can see, if a user types "0" as one of the values, the obvious "Cannot divide by zero" error appears. I would like some advice on how to…
JSeal
  • 19
  • 1
  • 3
0
votes
1 answer

SQL Stored Procedure Divide by zero error encountered.

Trying to figure out why my stored procedure is giving me a "divide by zero" error and I've narrowed it down to this area. If I comment the follow lines out the query runs successfully. I am not sure why though. …
devfunkd
  • 3,164
  • 12
  • 45
  • 73
0
votes
2 answers

Why does 1/inf == 0 but 1/0 != inf?

In general, 1/a = b ⟺ 1/b = a, so if we're letting the reciprocal of infinity be 0, the reciprocal of 0 should be infinity. It seems strange for Python to use the limit for 1/inf but not for 1/0. What is the rationale behind this decision?
Zaz
  • 46,476
  • 14
  • 84
  • 101
0
votes
1 answer

Floating point division by zero on showmodal Delphi XE8

I recently upgraded my application from Delphi 2007 to Delphi XE8. In couple of forms, Form.showmodel line throws "Floating point division by zero" exception. On those forms there is No arithmetic operations done at all. I tried executing following…
DivX
  • 103
  • 8
0
votes
1 answer

Easy SQL Divide By Zero Occurring when Syntax Seems Correct

I am using the following syntax: Case When acdtime != 0 Then sum(CAST(ti_stafftime as DECIMAL)/acdtime)*100 Else '0' End as MyPercent, Yet I am still getting this error: Msg 8134, Level 16, State 1, Line 3 Divide by zero error…
CodingIsAwesome
  • 1,946
  • 7
  • 36
  • 54