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)
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 dunno this is getting out of my area...
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)
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.
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)
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++