Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
fourwood
Sep 9, 2001

Damn I'll bring them to their knees.

clearly not a horse posted:

EDIT: In hindsight, ignore this post and treat it like poo poo. The problem was just division by zero. :ughh:


I am having a small problem with floating point numbers here, and I know I am doing something terribly wrong - I just need help to point out the error.

Below is a small function for generating a crude approximation of eulers number, where a fraction of (1/n) is added for each iteration. I may be even wrong with my approach, but the point is the error I get during interpretation.

code:
from math import *

def e (depth):
    base = 1.0
    for n in range(depth):
        base += 1.0/n
        print base

When I run the function, I get this error:
File "/Applications/WingIDE.app/Contents/MacOS/src/debug/tserver/_sandbox.py", line 6, in e
ZeroDivisionError: float division

You may want to double check your math. Summing 1/n doesn't give you what you think it gives you. You shouldn't get division by zero even when n = 0.

Adbot
ADBOT LOVES YOU

  • Locked thread