Mail Archives: djgpp/2001/10/14/03:36:08
On Thu, 11 Oct 2001 08:35:03 -0400, "Patrick Mitran"
<pmitran AT tsp DOT ece DOT mcgill DOT ca> wrote:
>> could you please suggest a name for a library whose code is not very long,
>> and that's all in C (again, not necessarily efficient!) we especially need
>> the division, and modulo operators...
>
>Why not just make the computer do long division (like you do it by hand) in
>binary?
>Its pretty easy since the divisor only ever fits in what you're dividing
>either 0 or 1
>times (compared to 0 to 9 times in decimal) and the algorithm only requires
>right shifts and substractions. As a bonus, you get the remainder (modulus)
>as well at the same time.
For arbitrary precision, you can probably implement byte size
(base 256) polynomial arithmetic fairly easily, as the products
fit easily in any int. Use an extra byte for the sign to keep
things easier. Don't have any refs, try a google search on
arbitrary precision arithmetic or look at the source for dc(1).
Did it in Basic functions using strings years ago and it's not
hard to do. It's easier to do with byte sizes than bits (too low
level) or half words (worrying about overflow).
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
--
Brian DOT Inglis AT CSi DOT com (Brian dot Inglis at SystematicSw dot ab dot ca)
fake address use address above to reply
tosspam AT aol DOT com abuse AT aol DOT com abuse AT yahoo DOT com abuse AT hotmail DOT com abuse AT msn DOT com abuse AT sprint DOT com abuse AT earthlink DOT com abuse AT cadvision DOT com abuse AT ibsystems DOT com uce AT ftc DOT gov
spam traps
- Raw text -