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
1 answer

SQL divide by zero in nested CASE statement

In this example, where Field1 - Field2 can equal 0 and will, how to I add another condition so that it continues with evaluating the conditions to compute the THEN when Field1 - Field2 does not equal zero? CASE WHEN (100 * ((Field1 - Field2) /…
Jeff 36
  • 1
  • 1
0
votes
0 answers

Why does 1/(0.9-0.3-0.3-0.3) return a high number?

Note: This question has code snippets in python, but applies to most languages which throw an error or return false when dividing by 0. I encountered this code yesterday: print(1/(0.9-0.3-0.3-0.3)) Which gives the strange…
Nico A
  • 227
  • 1
  • 14
0
votes
3 answers

Dividing by Zero while Generating List in Python

I am trying to make a list of percents generated by User-Input into the table. The table is working and has inputs from e1 - e24. The problem is that some of the inputs are zero, and thus my program stops when it runs into the error. Here is the…
jenryb
  • 2,017
  • 12
  • 35
  • 72
0
votes
3 answers

Why does my code throw an ArithmeticException when I expect it to simply print "Error"?

I have made a program that asks the user to enter two numbers, and it should give an error if the second number is a 0. However, I am getting an error, which is below. I have an if-else statement but it's not doing what I expect it to. I'm not sure…
Frank
  • 137
  • 9
0
votes
0 answers

Why did the order of my script give a Divide by Zero error?

I'm working on some beginner Python exercises. I have the following, working code: # Use the file name mbox-short.txt as the file name fname = raw_input("Enter file name: ") fh = open(fname) inp=fh.readlines() count=0 total=0.0 for line in inp: …
AwfulPersimmon
  • 175
  • 2
  • 14
0
votes
1 answer

_controlfp does not prevent DivideByZeroException

I wrote the following lines in C# using System; using System.Runtime.InteropServices; namespace ConsoleApplication1 { class Program { [DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)] extern static uint…
0
votes
1 answer

Divide-by-zero encountered: rhok assumed large error using scipy.optimizor

I used scipy.optimize.fmin_bfgs to minimize the hinge loss (SVM). However, there are errors : Divide-by-zero encountered: rhok assumed large. Somebody said that “It had to do with the training data set”, anybody knows how to deal with the…
ryyral
  • 3
  • 1
0
votes
1 answer

Dividing by zero in a boolean expression

I'm writing a program in Java, and I noticed that I had an expression in my code x / y > 0 that was evaluating to false when y == 0. I have since corrected this line in my code, but I'm curious, does anyone know why x / y > 0 evaluates to false…
Rootbeer
  • 13
  • 1
  • 3
0
votes
2 answers

ArithmeticException division by zero... how to fix this method?

The purpose of this method is to iterate through a 2D array of integers called grid[][], and translate the integers based on the maximum and minimum values into a smaller range between 100 and 250 (the original minimum value becomes 100, the…
0
votes
1 answer

how to ignore a text sting in a formula in Excel

I am using the formula: =IF(J1939=0,"NO SALES",((C1939*C1940)+(D1939*D1940)+(E1939*E1940)+(F1939*F1940)+(G1939*G1940)+(H1939*H1940)+(I1939*I1940))/J1939) I am using the IF function to ensure I do not receive a #DIV/0 error. I am now receiving a…
0
votes
1 answer

Error raised in code that shouldn't run according to lazy evaluation

I have the following code as part of a function: px = x2 - x1 py = y2 - y1 pz = z2 - z1 div = px*px + py*py u = ((x0 - x1) * px + (y0 - y1) * py) / div the u= line returns RuntimeWarning: invalid value encountered in divide when run. This is…
Siyh
  • 1,747
  • 1
  • 17
  • 24
0
votes
1 answer

Google Spreadsheet: ImportXML and Divided by Zero Error

On Google Spreadsheet, I have several calculations based on data parsed by the importXML function. If the import function doesn't find any data, then many of my calculations are not working because of DIV/0 errors. Which is normal and fine. But,…
Bkyn
  • 483
  • 5
  • 17
0
votes
2 answers

Avoiding Divide By 0 Error With Multiple Case Statements

The following is part of a SELECT clause that is giving me divide by 0 error: (SUM([Hours])/(SUM(CASE WHEN J.Description <> 'I' THEN 1 ELSE 0 END)) The following is how I am rectifying the denominator for the divide by 0 error: CASE WHEN(SUM(CASE…
J.S. Orris
  • 4,653
  • 12
  • 49
  • 89
0
votes
1 answer

Java fraction calculator throws exception for division by zero when trying to simplify

I have the following class which I am trying to use to perform calculations between fractions however every now and again i get a division by zero exception from on the simplify function and i cannot work out why it is doing it public class Fraction…
Conor
  • 736
  • 1
  • 13
  • 33
0
votes
1 answer

divide by zero in simclist library

In the simclist link list library, I've run into a problem where division by zero occurs in the function list_findpos(). Normally I'm be hesitant to modify a widely used 3rd party library, and there must be good reason why it does what it does (I…
user1628622