Program for Computing sin x and cos x in Floating-Point Mode on the Minsk-1 Digital Computer
Abstract Generated abstract
This paper presents a modified subroutine for computing sine and cosine in floating-point mode on the Minsk-1 digital computer. It examines limitations of the existing standard routine, including loss of mantissa digits for small arguments, incorrect results for arguments with large orders, and a nonzero result for sin of negative zero. The proposed method retains more of the mantissa when evaluating the Chebyshev polynomial for sine with negative argument order, handles large orders by defined argument reduction behavior, and returns zero for sine at zero and multiples of 2 pi. The author reports improved accuracy for sine, especially for very small arguments, while noting that the cosine algorithm does not allow a comparable improvement.
Full Text
PROGRAM FOR COMPUTING $\sin x$ AND $\cos x$ IN FLOATING-POINT MODE ON THE “MINSK-1” DIGITAL COMPUTER
V. K. Kivran
(Presented by the scientific seminar of the DCSL, TPI)
On digital computers with fixed point, the computation of the trigonometric functions $\sin x$ and $\cos x$ in floating-point mode is usually carried out according to the following scheme.
The argument is represented on the scale $1 : 2\pi$, and its fractional part in denormalized form is brought to the interval $(-1;\ 1)$ by the known transformation
\[ z=\left(\left|\left|\frac{x}{2\pi}-\frac14\right|-\frac12\right|-\frac14\right)4 \tag{1} \]
for computing $\sin x$, and
\[ z=\left(\left|\frac{x}{2\pi}\right|-\frac12\left|-\frac14\right.\right)4 \tag{2} \]
for computing $\cos x$. The integer part of the argument is discarded.
Then, for the reduced argument, a Chebyshev interpolation polynomial is computed by Horner’s scheme
\[ (((((c_6 z^2+c_5)z^2+c_4)z^2+c_3)z^2+c_2)z^2+c_1)z+z. \tag{3} \]
The result is normalized.
According to this scheme, a standard subroutine was constructed also on the “Minsk-1” digital computer.
This SS has a number of shortcomings.
First, the Chebyshev polynomial is computed in fixed-point mode, which, when the order of the argument is negative, leads to simple truncation of the lower digits of the mantissa and, consequently, to an increase in the error of the computations.
Second, in view of certain features of the shift operations on the “Minsk-1” digital computer, the computed value of the function may turn out to be incorrect if the order of the argument exceeds 31 in absolute value.
And, moreover, for $x=-0$ the computed value of $\sin x$ is equal to $2^{-29}$, and not zero, which may be inconvenient in solving certain types of problems.
In the present work, a modernized SP for the functions $\sin x$ and $\cos x$ is proposed, in which the above-mentioned shortcomings have been eliminated.
First, in the proposed SP the Chebyshev polynomial for $\sin x$ with a negative order is computed not with a denormalized argument, but using its entire mantissa. For this purpose, in expression (3) multiplication by Horner’s scheme is performed by the square of the mantissa of the argument, with a subsequent shift of the result by the doubled order. The computations of the polynomial for $\sin x$ with a positive order of the argument and for $\cos x$ are still carried out in fixed-point mode, which in this case is equivalent to floating point.
Thus, the error in computing the polynomial together with the reduction of the argument according to formulas (1) and (2), owing to the programming techniques used in the proposed subroutine, is limited to only two or three low-order digits, which is considerably less than the mean error of interpolation of the function by the polynomial.
Second, the computed value of the function is correct for any order of the argument, since in computing $\sin x$ with a positive order and $\cos x$ the argument is taken to be zero if the order exceeds 31 in absolute value.
Third, in the proposed subroutine the value of the function $\sin x$ is taken to be zero if the argument is equal to zero or is a multiple of $2\pi$ with either sign.
In conclusion it should be noted that the use of more careful programming techniques has considerably increased the accuracy of computing $\sin x$, especially for very small arguments. It is not possible to increase the accuracy of computing $\cos x$, since the given algorithm for computing $\cos x$ does not permit this.
The appendix gives the program with brief explanations.
Appendix. Program for computing $\sin x$ and $\cos x$ with floating point on the Minsk-1 digital computer.
The order of the argument is placed at address 0020, the mantissa at 0021, and the value of the function respectively at 0022 and 0023.
For computing $\sin x$, entry into the SP is made at address 2000; for computing $\cos x$, at 2002.
| Address | Code | Operand 1 | Operand 2 | Explanation |
|---|---|---|---|---|
| 2000 | 11 | 0004 | 0012 | entry for computing $\sin x$, |
| 1 | 24 | 2003 | 0023 | |
| 2 | 05 | 0000 | 0023 | entry for computing $\cos x$, |
| 3 | 03 | 2050 | 0021 | argument in fractions of a circle, |
| 4 | 16 | 0023 | 0020 | from 2006 $\sin x$ is computed with $p \geq 0$ |
| 5 | 54 | 2006 | 2017 | and $\cos x$, while from 2017—$\sin x$ with $p < 0$, |
| 6 | −17 | 2033 | 0020 | |
| 7 | 54 | 2012 | 2012 | removal of the restriction |
| 2010 | 05 | 0000 | 0021 | on the order of the argument, |
| 1 | 24 | 2016 | 0000 | |
| 2 | −07 | 0020 | 0021 | denormalization of the argument and |
| 3 | 54 | 2016 | 2015 | reduction of it to the interval $(0; 1)$; |
| 4 | 24 | 2016 | 0000 | |
| 5 | 20 | 0001 | 0021 | |
| 6 | 05 | 0000 | 0020 | |
| 7 | −27 | 0012 | 0022 | doubling the order $(2p_z)$, |
| 2020 | 10 | 0023 | 0021 | |
| 1 | 71 | 0002 | 0000 | computation of $q_z/2$, |
| 2 | 71 | 2057 | 0000 | |
| 3 | −27 | 0012 | 0021 |
| 4 | −27 | 0012 | 0024 | |
| 5 | 23 | 0024 | 0024 | |
| 6 | −17 | 2033 | 0022 | $\sin x = 0$, if $\lvert p_z\rvert > 31$, |
| 7 | 54 | 0000 | 2042 | |
| 2030 | 05 | 2046 | 2034 | computation of the polynomial |
| 1 | 05 | 2051 | 0023 | with $p_z \leqslant 0$, |
| 2 | 13 | 0024 | 0023 | |
| 3 | −37 | 0022 | 0005 | |
| 4 | 20 | 2052 | 0023 | |
| 5 | 00 | 0011 | 2034 | |
| 6 | −71 | 2047 | 0000 | |
| 7 | 54 | 2032 | 0000 | |
| 2040 | 13 | 0021 | 0023 | |
| 1 | 20 | 0021 | 0021 | |
| 2 | 15 | 0021 | 0022 | |
| 3 | 10 | 0020 | 0022 | normalization of the result, |
| 4 | 20 | 0012 | 0022 | |
| 5 | 24 | 0027 | 0000 | |
| 6 | 20 | 2052 | 0023 | pseudocommands, |
| 7 | 20 | 2057 | 0023 | |
| 2050 | 12 | 1371 | 4067 | $1/2\pi$, |
| 1 | −00 | 0000 | 7130 | $c_6$, |
| 2 | 00 | 0052 | 0011 | $c_5$, |
| 3 | −00 | 2313 | 2060 | $c_4$, |
| 4 | 05 | 0632 | 7370 | $c_3$, |
| 5 | −51 | 2567 | 4711 | $c_2$, |
| 6 | 44 | 4176 | 6520 | $c_1$, |
| 7 | 20 | 0000 | 0001 | $1/4 - 2^{-30}$. |
LITERATURE
- Library of standard subprograms for the Minsk-1 digital computer, Part II, Minsk, 1961.