
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 03/30/2010 11:39 AM, Scott McMurray wrote:
Which isn't necessarily the best way to do it, and certainly isn't the only one. There is effectively zero runtime cost for XInt's exception-blocking mechanism, since the code used for it is only evaluated when an exception needs to be thrown.
There is, however, conceptual and infrastructure overhead from supporting it.
First, there's the fact I've previously mentioned than NaN weakens the invariant of the xint type. This requires extra effort in specifying functions that take and return xints. The most obvious evidence of this is the fact that almost every function in the library has the following line in its documentation: "Can throw: xint::not_a_number if n is Not-a-Number."
Sorry, but I can't agree. You, the person using the XInt library, don't have to write any code to handle NaNs, unless you either explicitly block exceptions or call one of the two functions that can normally return them. If some other code passes yours a NaN, or blocks exceptions before calling yours so that you get a NaN when you don't expect one, the library will throw the exception for you, the first time you use it in any function.
Second, the blocking is stateful. That means that if I write another library that accepts xints, I'll have to either write every function to work no matter the blocking mode or change it to what I want to work with. This state maintenance means bringing in the threading complications that are otherwise unnecessary.
Now that's an argument I can finally agree with. :-) Here's how I propose to solve it: make a "core" version of the integer class and functions, with no exception-blocking and no Not-a-Number value, in the namespace xint::core. Then make the main integer class and functions in namespace xint, with exception-blocking, the Not-a-Number value, and maybe infinity values. If you want to write something like an arbitrary floating-point library on top of XInt, you do so using the class and functions from xint::core, and deal solely with exceptions. If you just want to use XInt, with all the bells and whistles, you use the functions in the xint namespace. Will that satisfy your concerns? - -- Chad Nelson Oak Circle Software, Inc. * * * -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkuyZ30ACgkQp9x9jeZ9/wSqHQCg9MJlErQZM8e5qes5kMKxk6vG Fl0AoL2QOD8ulWmxtSarzkEzeqe41iU7 =iLcA -----END PGP SIGNATURE-----