b3ta.com board
You are not logged in. Login or Signup
Home » Messageboard » Message 8532362 (Thread)

# Is there no alternative?
Or will that involve working out what the largest possible number is, then using that instead of 0?
(, Sun 6 Jul 2008, 12:38, archived)
# Pretty much.
You have to keep saying "Wait! Is that input zero? In that case don't try the calculation, you'll only get upset. Here, I'll do it for you, the answer is such-and-such."
(, Sun 6 Jul 2008, 12:41, archived)
# Bah.
That sounds thrilling.
(, Sun 6 Jul 2008, 12:43, archived)
# bloody programmers :P
C is a pain in the arse at the best of times but can't you actually redefine the NaN to be the maximum?

I dunno this is getting out of my area...
(, Sun 6 Jul 2008, 12:46, archived)
# I think that causes portability problems
in that you can't rely on being able to do it with different chips, operating systems, libraries or whatever.

I might be wrong, though, maybe in the modern age we should in fact be doing exactly this and all the examples I see that catch divide by zero errors are just being anal.
(, Sun 6 Jul 2008, 12:56, archived)
# there's no harm in writing your own library that does a manual test
kind of:
int funkydiv (int a, int b) {
if(b == 0) return MAX; else return a/b;
}

so long as you make sure it's distinguished from the built-in int type. also, i don't know what c's like for overloading operators, but it'd be a piece of piss to overload the division operator in c++
(, Sun 6 Jul 2008, 13:22, archived)
# Fair point.
(, Sun 6 Jul 2008, 13:27, archived)
# i write infrastructure for dsp engineers sometimes
they can be fussy about their maths
(, Sun 6 Jul 2008, 13:38, archived)