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
3 answers

Why the output of printf("%d",1/0.0) is 0?

I use the codeblock. When the code is: printf("%d",1/0); The program can not run, there is an error. But when I write this: printf("%d",1/0.0); The program can run,and the output is 0. I want to know why.
0
votes
5 answers

Appropriate behaviour to prevent division by zero

We have been asked to design a Vector3D class using memory on the stack. I need to divide the vector by a scalar, but what is the most appropriate behavior to prevent a divide by zero? I could throw an exception? I don't want to return a Vector3D of…
user2406944
0
votes
3 answers

Illegal division by zero on very simple script

A simple perl script: #!/usr/bin/perl $num = `sed "s/\([^ ]*\).*/\1/"`; print "$num"; $total = `sed "s/[^ ]*\(.*\)/\1/"`; print "$total"; $div = $num / $total; print "div = $div \n"; When I run it: $ echo 4 10 | ./test.pl 4 10 Illegal division…
Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130
0
votes
2 answers

Divide by Zero Anomaly in PHP

Okay, so I was playing around with the idea of a stack overflow loop. I entered the following code and got a cute little image in Google Chrome (their answer for a 500 internal error which is NOT helpful by the way Google!). This was as expected…
AbsoluteƵERØ
  • 7,816
  • 2
  • 24
  • 35
0
votes
1 answer

For Loop with Bool

I have a simple loop which gets stuck on a division by zero error. I am running a bool to filter out zero-value denominators, but for some reason the bool I used isn't working. Can someone please help? I am using python 2.6.5 Here is a sample…
teachamantofish
  • 75
  • 1
  • 1
  • 7
0
votes
1 answer

ZeroDivisionError: float division by zero when computing standard deviation

I've isolated a problem in my script that is occurring due to this attempt at a standard deviation calculation using scipy's .tstd function, sp.stats.tstd(IR) where my IR value is 0.0979. Is there a way to get this to stop (I assume) rounding it…
Matt
  • 3,508
  • 6
  • 38
  • 66
0
votes
1 answer

Division by zero with positive or no divisor (vba)

I'm new to macros and vba in Excel. Currently, I'm working on a vba macro for an invoice template at work. However, I'm running in a division by zero error that I'm having trouble tracing the cause of. There are two specific lines of code where it…
Martin
  • 57
  • 8
0
votes
1 answer

Xcode crashes with divide by zero

I downloaded urlcache.zip from http://developer.apple.com/iphone/library/samplecode/URLCache/index.html#//apple_ref/doc/uid/DTS40008061 I opened the project in xcode and clicked on urlcacheconection.m and started scrolling down with the arrow key…
axe
  • 27
  • 3
  • 5
0
votes
1 answer

How to avoid division by zero error, when performing calculations on parsed xml data

please be kind with your answers I have been coding now for 10 days. I am having trouble with performing loops in my code, but I am fairly certain this is because I am getting a traceback. I parse an xml file obtained from a url, using the…
AEA
  • 213
  • 2
  • 12
  • 34
0
votes
2 answers

Normalize vector by zero

I am working on designing a new sensor, and so I have a vector of measured values and a vector of truth values. To represent error, it's simply measured - truth. Since there's a lot of variation in the truth, I would like to represent the…
David K
  • 1,296
  • 18
  • 39
0
votes
1 answer

awk log2 division/ ratio zero

I have a csv file that looks like this: ID1 ID2 AVG1 AVG2 ENSG00000207447 RNU6-2 0.101431 0.163308 ENSG00000207427 SNORA51 0.096551 0 ENSG00000201784 SNORD14A 0.068653 0.0320985 …
user1879573
  • 251
  • 3
  • 14
0
votes
4 answers

Why exceptions have to be thrown manually?

I have tried this in PHP and C++ so my question is specifically about them only. Why do we have to throw exceptions ourself and they are not thrown automatically when an exception issue occurs. PHP Code First
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
0
votes
2 answers

GAS assembly snippet divides by 0, not sure why

I have the following function, involving a snippet of i386 assembly in GAS syntax: inline int MulDivRound( int nNumber, int nNumerator, int nDenominator ) { int nRet, nMod; __asm__ __volatile__ ( "mov %2, %%eax …
benwad
  • 6,414
  • 10
  • 59
  • 93
0
votes
1 answer

Perl illegal division by zero

I am trying to run this Perl program. #!/usr/bin/perl # --------------- exchange.pl ----------------- &read_exchange_rate; # read exchange rate into memory # now let's cycle, asking the user for input... print "Please enter the…
kirbyfan64sos
  • 10,377
  • 6
  • 54
  • 75
0
votes
0 answers

Division by zero while getting divide post result and array sum

In my Models : function input() { $vendor = $this->input->post('vendor'); for($i=1;$i<=$vendor;$i++) { for($j=1;$j<=$vendor;$j++) { $delivery[$j] = $this->input->post('delivery_1_'.$j.'_'.$i); …