The need for D-scussion (was Re: D Wishlist)

Karl Heuer karl at haddock.ISC.COM
Mon Mar 21 06:07:06 AEST 1988


In article <27143 at linus.UUCP> bs at gauss.UUCP (Robert D. Silverman) writes:
>I am a computational number theorist who writes a LOT of code requiring that:
>A*B/C [and] A*B%C be computed where A,B,C are all 30 bit quantities.  The
>difficulty is that even though the algorithm guarantees that the results of
>the computations fit in 30 bits, the product A*B may not. I therefore need to
>make extensive use of any 'emul' and 'ediv' facilities that a computer may
>have. ... Machines which have such instructions should, In my opinion,
>generate emul/ediv code whenever it sees A*B/C and only return a run-time
>arithmetic overflow if the quotient doesn't fit in the appropriate word-size.

Such a special case would be a wart in the language.  The "correct" way to do
this is to provide an "lmuldiv" function which has the desired semantics (I'd
have it return an ldiv_t structure, since it already exists in ANSI C), and
encourage vendors to give their compilers the ability to inline it (along with
other trivial functions, such as abs()).

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list