background image

8-22 Vol. 1

PROGRAMMING WITH THE X87 FPU

reduction and other computations, denoted as Pi in the expression below. The numerical value of Pi can be written 
as:

Pi 

= 0.f ∗ 2

2

where the fraction f is expressed in binary form as:

f = C90FDAA2  2168C234  C

(The spaces in the fraction above indicate 32-bit boundaries.)
The internal approximation Pi of the value π has a 66 significant bits. Since the exact value of π represented in 

binary has the next 3 bits equal to 0, it means that Pi is the value of π rounded to nearest-even to 68 bits, and also 

the value of π rounded toward zero (truncated) to 69 bits.
However, accuracy problems may arise because this relatively short finite approximation Pi of the number π is used 

for calculating the reduced argument of the trigonometric function approximations in the implementations of FSIN, 
FCOS, FSINCOS, and FPTAN. Alternately, this means that FSIN (x), FCOS (x), and FPTAN (x) are really approxi-
mating the mathematical functions sin (x * π /Pi), cos (x * π / Pi), and tan (x * π / Pi), and not exactly sin (x), cos 

(x), and tan (x). (Note that FSINCOS is the equivalent of FSIN and FCOS combined together). The period of sin (x 
* π /Pi) for example is 2* Pi, and not 2π. 
See also Section 8.3.10, “Transcendental Instruction Accuracy” for more information on the accuracy of these func-
tions.

8.3.9 

Logarithmic, Exponential, and Scale

The following instructions provide two different logarithmic functions, an exponential function and a scale function:

FYL2X

Logarithm

FYL2XP1

Logarithm epsilon

F2XM1

Exponential

FSCALE

Scale

The FYL2X and FYL2XP1 instructions perform two different base 2 logarithmic operations. The FYL2X instruction 
computes (y ∗ log

2

x). This operation permits the calculation of the log of any base using the following equation:

log

b

 

x = (1/log

b) ∗ log

2

 x

The FYL2XP1 instruction computes (y ∗ log

2

(x + 1)). This operation provides optimum accuracy for values of x that 

are close to 0.
The F2XM1 instruction computes (2

x

 − 1). This instruction only operates on source values in the range −1.0 to +1.0.

The FSCALE instruction multiplies the source operand by a power of 2.

8.3.10 

Transcendental Instruction Accuracy

New transcendental instruction algorithms were incorporated into the IA-32 architecture beginning with the 
Pentium processors. These new algorithms (used in transcendental instructions FSIN, FCOS, FSINCOS, FPTAN, 
FPATAN, F2XM1, FYL2X, and FYL2XP1) allow a higher level of accuracy than was possible in earlier IA-32 processors 
and x87 math coprocessors. The accuracy of these instructions is measured in terms of units in the last place 
(ulp). For a given argument x, let f(x) and F(x) be the correct and computed (approximate) function values, 
respectively. The error in ulps is defined to be:

where is an integer such that:

error

f x

( ) F x

( )

2

k

63

---------------------------

=

1

2

k

f x

( ) 2.

<