home *** CD-ROM | disk | FTP | other *** search
/ PC Media 2 / PC MEDIA CD02.iso / share / prog / realasm1 / ftcos.asm < prev    next >
Encoding:
Assembly Source File  |  1993-07-18  |  2.0 KB  |  56 lines

  1. .286
  2. ;================================================
  3. ; invoke ftcos, real, radians
  4. ;
  5. ; Returns real = cos(radians)
  6. ;------------------------------------------------
  7. ;              x**2     x**4     x**6
  8. ; cos x = 1 -  ----  +  ----  -  ----  +  .......
  9. ;               2!       4!       6!
  10. ;
  11. ; 8 terms give 18 significant decimal places for
  12. ; an angle of 45 degrees.
  13. ;------------------------------------------------
  14. cseg          segment word public 'code'
  15.               assume  cs:cseg,ss:cseg
  16.               assume  ds:cseg,es:cseg
  17.  
  18.               include math.inc
  19.  
  20. ftcos         proc    near  real:NPR10, radians:NPR10
  21.               local   p:REAL10, f:REAL10
  22.  
  23.               pusha                             ;
  24.               mov     si, real                  ;
  25.               mov     di, radians               ;
  26.  
  27.               invoke  load1, si                 ; real = 1.0
  28.               xor     bx, bx                    ; BX = 0
  29.               mov     cx, 8                     ; number of terms
  30.               mov     dx, 2                     ; starting power, factorial
  31.  
  32.               .WHILE (cx)                       ;
  33.                  invoke movx, addr p, di, 5     ; p = radians
  34.                  invoke ftpower, addr p, dx     ; p = p**dx
  35.                  invoke ftfact, addr f, dx      ; f = factorial dx
  36.                  invoke ftdiv, addr p, addr f   ; p = p**dx / factorial dx
  37.  
  38.                  xor    bx, 1                   ;
  39.                  .IF (bx == 1)                  ;
  40.                     invoke ftsub, si, addr p    ; - term
  41.                  .ELSE                          ;
  42.                     invoke ftadd, si, addr p    ; + term
  43.                  .ENDIF                         ;
  44.  
  45.                  add     dx, 2                  ; powers, factorials + 2
  46.                  dec     cx                     ; continue
  47.               .ENDW
  48.  
  49.               popa
  50.  
  51.               ret
  52. ftcos         endp
  53.  
  54. cseg          ends
  55.               end
  56.