From: Guillaume Melquiond (guillaume.melquiond_at_[hidden])
Date: 2006-05-17 11:31:51
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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk