Free Republic
Browse · Search
News/Activism
Topics · Post Article

To: JamesP81
Declare the pointer to the value to be null after exception handling the divide by zero error.

What does that have to do with the value of nullity?

Either that, or we determine that the lowest value for a given variable or its highest possible value (either –2,147,483,648 or 2,147,483,647 since we're using 32 bit signed integers) to be a divide by zero condition.

By "divide by zero condition" do you mean "nullity"? If that's the case, we have to do that for all types (signed and unsigned 8-bit, 16-bit, 32-bit, 64-bit integer values, floats, doubles, etc.). Now all of a sudden "nullity" is represented by many different values depending on the data type. That just doesn't make sense!

It doesn't fall on the number line, so it is impossible to represent using binary unless you special case the value, which is what you're doing in your code now to avoid divide by zero errors. So defining "nullity" doesn't help you at all in your programs. You're better off doing precondition checking to insure you don't divide by zero, or handling it after the fact by catching the exception.

127 posted on 12/08/2006 1:22:40 PM PST by vrwc1
[ Post Reply | Private Reply | To 100 | View Replies ]


To: vrwc1
You're better off doing precondition checking to insure you don't divide by zero, or handling it after the fact by catching the exception.

That's pretty much what I just said.

Exception handling is usually all that's needed unless for some reason you need to retain the fact that you divided by zero later in the code. That's not too common, but not unheard of either.

If you do need to retain a divide by zero in memory, pointers in most programming languages help you out. In most languages, pointers can be set to null (with 'null' being a reserve word). I don't know what the binary code behind this is, but it doesn't matter. What matters is that I can set a pointer to null if I divide by zero, and that's a special case that works no matter what. Most languages that do this also overload the '=' operator so you can test if a pointer's value is null.

As for special casing based on data type, if I absolutely have to do that (and never have, at least not in my professional work that I can remember), I'll try to use the same length (8 bit, 16 bit, etc) for all my variables if memory permits. Not very efficient or clean but it can be done if you have to retain a divide by zero when the language you're using doesn't let you set a pointer equal to null. At least then you only need to set two special cases; one for integers and one for reals.
140 posted on 12/08/2006 1:31:24 PM PST by JamesP81 (If you have to ask permission from Uncle Sam, then it's not a right)
[ Post Reply | Private Reply | To 127 | View Replies ]

Free Republic
Browse · Search
News/Activism
Topics · Post Article


FreeRepublic, LLC, PO BOX 9771, FRESNO, CA 93794
FreeRepublic.com is powered by software copyright 2000-2008 John Robinson