Annotation of coherent/b/lib/libm/i8087/tan87.m, revision 1.1.1.1

1.1       root        1: //////////
                      2: / libm 8087
                      3: / tan(d)
                      4: //////////
                      5: 
                      6: #include "larges.h"
                      7: #include "ifno8087.h"
                      8: 
                      9:        .globl  tan_
                     10:        .globl  tan
                     11:        .globl  cfcc87
                     12:        .globl  tstcc
                     13: 
                     14: //////////
                     15: / double
                     16: / tan(angle)
                     17: / double angle;
                     18: //////////
                     19: 
                     20: d      =       RASIZE          / arg offset
                     21: 
                     22: tan_:
                     23:        ifno8087(_tan_)
                     24:        mov     bx, sp
                     25:        fdld    Pss d(bx)       / Load argument d.
                     26: 
                     27:        Gcall   tan             / Get x, y.
                     28:        fdiv                    / tan  = y / x.
                     29:        Gret
                     30: 
                     31: //////////
                     32: / tan() is passed an argument d on the 8087 stack
                     33: / and returns x and y on 8087 stack.
                     34: /
                     35: / tan() reduces angle d to octant 0,
                     36: / uses fptan to get a sine y and cosine x,
                     37: / and puts x and y back to the correct octant.
                     38: /
                     39: / Uses fptan, which requires 0 <= d < pi/4.
                     40: //////////
                     41: 
                     42: tan:                           / d
                     43:        fild    cs:minus2       / -2, d
                     44:        fldpi                   / pi, -2, d
                     45:        fscale                  / pi/4, -2, d
                     46:        fstp    st1             / pi/4, d
                     47:        fxch                    / d, pi/4
                     48: 
                     49: 0:     Gcall   tstcc           / Is d < 0.?
                     50:        jnb     1f              / No, ok.
                     51:        fldpi
                     52:        fld     st
                     53:        fadd
                     54:        fadd                    / Add 2 * pi.
                     55:        jmp     0b              / Repeat until d is positive.
                     56: 
                     57: 1:     fprem                   / Reduce angle to octant 0.
                     58:        Gcall   cfcc87          / Set condition codes.
                     59:        jpe     1b              / Repeat until fully reduced.
                     60:        fstp    st1             / Pop pi/4, retain reduced arg.
                     61:        fptan                   / x = r*cos(arg), y=r*sin(arg)
                     62: 
                     63: / cos(pi+d) = -cos(d), sin(pi+d) = -sin(d).
                     64:        jnc     2f              / Test for c0 set by cfcc87 above.
                     65:        fchs                    / Octants 4, 5, 6, 7
                     66:        fxch                    / need both
                     67:        fchs                    / signs
                     68:        fxch                    / changed.
                     69: 
                     70: / cos(pi/2+d) = -sin(d), sin(pi/2+d) = cos(d).
                     71: 2:     jnz     3f              / Test for c3 set by cfcc87 above.
                     72:        fxch                    / Octants 2, 3, 6, 7
                     73:        fchs                    / need switch and sign change.
                     74: 
                     75: / cos(pi/4+d) = (cos(d)-sin(d))*k, sin(pi/4+d) = (cos(d)+sin(d))*k.
                     76: 3:     testb   ah, $2          / Test for c1 set by cfcc87 above.
                     77:        jz      4f              / Done.
                     78:        fld     st              / Octants 1, 3, 5, 7
                     79:        fld     st2             / need x-y and x+y.
                     80:        fadd                    / x+y, x, y
                     81:        fxch    st2             / y, x, x+y
                     82:        fsub                    / x-y, x+y
                     83: 
                     84: 4:     Gret
                     85: 
                     86: //////////
                     87: / data
                     88: //////////
                     89: minus2:        .word   -2

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.