|
Boost : |
From: Victor A. Wagner, Jr. (vawjr_at_[hidden])
Date: 2002-08-21 01:39:05
At Tuesday 2002/08/20 21:45, you wrote:
>The question of how to support the double word results of
>multiplying two words ecently came up on the C++ committee
>reflector. The choices seem to be either providing a special
>function, or providing typedefs for which idioms like the
>following can result in optimal code:
>
> uword_t x, a;
> ulong_t y = ulong_t(x) * a;
>
>To which we can add:
> uword_t b;
> ulong_t y = ulong_t(x) * a / b;
>
>I should think that most compilers already do a good job,
>given suitable choices of uword_t and ulong_t, but I haven't
>done any testing to find out.
This is also one of my pet peeves about a language that purportedly lets
you code "down to the sand".
also missing is the concept of carry or overflow that is readily detectable
at the language level.
The _real_ problem isn't addressed by Band-Aids like the BCPL muldiv(x, a,
b) but at least THAT language had it as part of the standard library.
The problem is exactly like every other problem we have in this biz....
someone got there "first with the worst" and we can't recover from it. The
_only_ reasonable thing would be to make the expression y = x * a / b;
work like it does when you code it in assembly on most machines.
BUT.... that wouldn't be backwards compatible, so we're stuck with "worst".
If the committee is seriously considering ways to handle stuff, how about
dealing with the two results returned by almost every integer divide
instruction... quotient and remainder.
[deleted]
Victor A. Wagner Jr. http://rudbek.com
PGP RSA fingerprint = 4D20 EBF6 0101 B069 3817 8DBF C846 E47A
PGP D-H fingerprint = 98BC 65E3 1A19 43EC 3908 65B9 F755 E6F4 63BB 9D93
The five most dangerous words in the English language:
"There oughta be a law"
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk