BigInt divide-by-zero handling

I'm planning to finish the BigInt library for SoC. I'm looking for some input about whether divide-by-zero should throw an exception, or just store a NaN and propagate that through any subsequent operations. Since ordinary ints just throw an exception, and my goal is to make BigInts have virtually the same interface as ints but never overflow, it seems reasonable to throw an exception. Any objections? Cheers, Jonathan Ray

Since ordinary ints just throw an exception, and my goal is to make
I don't think ordinary ints throw exceptions. Nevertheless, I think you should. Regards, -Gerhard -- Gerhard Wesp ZRH office voice: +41 (0)44 668 1878 ZRH office fax: +41 (0)44 200 1818 For the rest I claim that raw pointers must be abolished.

Jonathan Ray escreveu:
I'm planning to finish the BigInt library for SoC. I'm looking for some input about whether divide-by-zero should throw an exception, or just store a NaN and propagate that through any subsequent operations. Since ordinary ints just throw an exception, and my goal is to make BigInts have virtually the same interface as ints but never overflow, it seems reasonable to throw an exception. Any objections?
std::logic_error comes to mind. -- Pedro Lamarão Desenvolvimento Intersix Technologies S.A. SP: (55 11 3803-9300) RJ: (55 21 3852-3240) www.intersix.com.br Your Security is our Business

Le mardi 16 mai 2006 à 17:10 -0500, Jonathan Ray a écrit :
I'm planning to finish the BigInt library for SoC. I'm looking for some input about whether divide-by-zero should throw an exception, or just store a NaN and propagate that through any subsequent operations. Since ordinary ints just throw an exception, and my goal is to make BigInts have virtually the same interface as ints but never overflow, it seems reasonable to throw an exception. Any objections?
A division by zero for BigInt could also be undefined (in the C++ Standard sense of the word), as is the integer division. This is the behavior chosen by GMP and users seem quite happy with it. As for the implementation of this undefinedness, GMP causes an intentional "hardware" division by zero. So, from an external/runtime point of view, there is no difference between a program computing with int or mpz_t when there is a division by zero, and it can be handled the exact same way. I think having the same behavior for all the integer types (be they primitive int or user-defined BigInt) is a nice feature. So throwing an exception does not really make it for me. Best regards, Guillaume
participants (4)
-
Gerhard Wesp
-
Guillaume Melquiond
-
Jonathan Ray
-
Pedro Lamarão