FPREM           Partial remainder                    Exceptions: I D U
FPREM1 IEEE Partial remainder (387+) C3 C2 C1 C0: * * * *

FPREM
FPREM1

Logic ST ← remainder (ST / ST(1))

These instructions divide ST by ST(1), and put the remainder in ST.
The sign of the remainder is the same as the sign of the original
dividend in ST.
FPREM is supported for compatibility with the 8087 and 80287 math
coprocessors. The FPREM1 instruction is the remainder operation
specified in IEEE Standard 754.


An important use of FPREM/FPREM1 is to reduce the arguments of
periodic functions. When the reduction is complete, FPREM/FPREM1
provides the 3 least-significant bits of the quotient in flags C3,
C1, and C0 (C0 = bit 2, C1 = bit 1, C3 = bit 0). This is important
in argument reduction for the tangent function (using a modulus of
PI/4), because it locates the original angle in the correct one of 8
sectors of the unit circle.


Note
FPREM and FPREM1 produce an exact result; the precision (inexact)
exception does not occur and the rounding control (RC) has no
effect.


Example
; Compute z := x MOD y
p387
fld [y]
fld [x]
@@again:
fprem1 ; compute IEEE partial remainder
fstsw ax ; get condition bits
test ah, 0100b ; if C2 is set
jnz @@again ; not done yet
fstp [z] ; store and pop remainder
fstp ST(0) ; unstack y


Opcode Format
D9 F8 FPREM
D9 F5 FPREM1


Timing
Variations 8087 287 387 486 Pentium
fprem 15-190 15-190 74-155 70-138 16-64 NP
fprem1 - - 95-185 72-167 20-70 NP