Boost logo

Boost :

Subject: Re: [boost] [xint] Boost.XInt formal review
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-03-13 19:06:57


AMDG

On 03/13/2011 07:45 AM, Thomas Klimpel wrote:
> Kim Barrett wrote:
>> Thomas Klimpel wrote:
>> Note that C99 tightened this up, requiring truncation toward zero behavior.
>> The latest C++0x working draft follows C99 in this respect, also requiring
>> truncation toward zero. I would hope (though haven't looked) that XInt
>> similarly performs truncation toward zero.
> OK, that's at least a step forward from "implementation-defined", but the modulo operator ("%") is still awkward to use in practice (for negative numbers).

If you don't like it, then you can always fix up
the result to be what you want. The cost of
adjusting the result is going to be a lot less than
the cost of the division itself. Not to mention
that the existing behaviour is the most natural
and efficient to implement for the signed-magnitude
representation that the library uses.

>> Regarding quotient / remainder computation,
>> I would think that an appropriate overload of std::div() would suffice.
>> I haven't looked to see if XInt provides such an overload.
> What would you use as return type for this overload? A std::pair, a boost::tuple, or a specially defined struct (std::div_t) like the other overloads from std?

It's already provided by the library. (Okay,
it's called divide, not div and it returns
integer<...>::divide_t)

>>> The point how this all is related to the XInt review is that on the one hand, XInt can't be blamed if it tries to follow the example from C/C++ for consistency reasons, but on the other hand, C/C++ is probably a poor example in this specific domain. Even Ada, which nobody likes for good reasons unrelated to this domain, does a much better job than C/C++ here.
>> If XInt follows C99 / C++0x here, does that answer your complaint?
> Probably not, because this was a complaint about C/C++, not about XInt. This complaint was in response to Steven asking "Are the basic operations that are provided not enough for some algorithm that you care about?". From my experience with C/C++, I could answer this question with a definitive "Yes, the basic operations provided by C/C++ for integer numbers are not enough for some algorithms that I care about!". I know that this is a review of XInt, but as I have much more experience with C/C++, it makes sense to answer this question for C/C++ instead, which XInt tries to follow for consistency reasons.

I'm afraid that what you've said doesn't help me at all
You've mentioned that you don't like the way division
is defined, and you've mentioned FFT's, but you haven't
made any attempt to explain how this is a real problem
for XInt. This isn't about implementability. An FFT can
be implemented using only basic math operations. It's
a matter of efficiency. And for this, you can't generalize
from the builtin types to XInt because the performance
characteristics are significantly different.

> I gave two specific example (I could give more, but I guess nobody wants to hear them, because it is not realistic to expect that this deficiency of C/C++ will ever be fixed), one directly related to the current review, and the other related to my own daily work.

In Christ,
Steven Watanabe


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk