Floating remainder (was Re: Assembly or ....)

Len Mills len at elxsi.UUCP
Thu Dec 1 06:45:42 AEST 1988


In article <1034 at l.cc.purdue.edu> cik at l.cc.purdue.edu (Herman Rubin) writes:
>> |In article <1032 at l.cc.purdue.edu> cik at l.cc.purdue.edu (Herman Rubin) writes:
>> |...
>> |> suppose we want to
>> |>divide a by b, obtaining an integer result i and a remainder c.  I know
>> |>of no machine with this instruction, and this is not that unusual an 
>> |>instruction to demand.  It is cheap in hardware, and extremely expensive
>> |>in software--at least 4 instructions.
>I do not know if I made it clear in my initial posting, but the problem
>arises if the types of a, b, and c are floating.  Not that the quote from
>my paper specifically has i an integer.

If I understand correctly, what you are looking for is a Floating Point
Remainder instruction.  The ELXSI 6400 series include the FREM instructions
for the various IEEE floating point formats.  The behavior of these
instructions is:

   Divide Rz by Ry to produce (for non-zero quotients) a new value in Rx
   which consists of the low-order 64 bits of the rounded two's complement
   integer quotient, and replacing Rz by the remainder in floating-point
   form.  The remainder is defined to be Rz - (( Rz/Ry rounded to the
   nearest integer) * Ry), such that -0.5 * abs (divisor) <= remainder <=
   +0.5 * abs (divisor).

Of course, the RISCyness of this design is open to debate (:-).


-- 

Len Mills ...
{uunet,ucbvax!sun,lll-lcc!lll-tis,altos86,bridge2}!elxsi!len



More information about the Comp.lang.c mailing list