home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / pmlsrc23.zoo / pmlsrc / csin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-19  |  4.2 KB  |  199 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *                N O T I C E                *
  4.  *                                    *
  5.  *            Copyright Abandoned, 1987, Fred Fish        *
  6.  *                                    *
  7.  *    This previously copyrighted work has been placed into the    *
  8.  *    public domain by the author (Fred Fish) and may be freely used    *
  9.  *    for any purpose, private or commercial.  I would appreciate    *
  10.  *    it, as a courtesy, if this notice is left in all copies and    *
  11.  *    derivative works.  Thank you, and enjoy...            *
  12.  *                                    *
  13.  *    The author makes no warranty of any kind with respect to this    *
  14.  *    product and explicitly disclaims any implied warranties of    *
  15.  *    merchantability or fitness for any particular purpose.        *
  16.  *                                    *
  17.  ************************************************************************
  18.  */
  19.  
  20. /*
  21.  *  FUNCTION
  22.  *
  23.  *    csin   complex double precision sine
  24.  *
  25.  *  KEY WORDS
  26.  *
  27.  *    csin
  28.  *    complex functions
  29.  *    machine independent routines
  30.  *    math libraries
  31.  *
  32.  *  DESCRIPTION
  33.  *
  34.  *    Computes double precision complex sine of a double
  35.  *    precision complex argument.
  36.  *
  37.  *  USAGE
  38.  *
  39.  *    COMPLEX csin (z)
  40.  *    COMPLEX z;
  41.  *
  42.  *  REFERENCES
  43.  *
  44.  *    Fortran 77 user's guide, Digital Equipment Corp. pp B-12
  45.  *
  46.  *  PROGRAMMER
  47.  *
  48.  *    Fred Fish
  49.  *    Tempe, Az 85281
  50.  *    (602) 966-8871
  51.  *
  52.  *  INTERNALS
  53.  *
  54.  *    Computes complex sine of z = x + j y from:
  55.  *
  56.  *        1.    r_csin = sin(x) * cosh(y)
  57.  *
  58.  *        2.    i_csin = cos(x) * sinh(y)
  59.  *
  60.  *        3.    csin(z) = r_csin + j i_csin
  61.  *
  62.  */
  63.  
  64. #if !defined (__M68881__) && !defined (sfp004)
  65.  
  66. #include <stdio.h>
  67. #include <math.h>
  68. #include "pml.h"
  69.  
  70. COMPLEX csin (z)
  71. COMPLEX z;
  72. {
  73.     COMPLEX result;
  74.  
  75.     result.real = sin (z.real) * cosh (z.imag);
  76.     result.imag = cos (z.real) * sinh (z.imag);
  77.     return (result);
  78. }
  79. #endif !defined (__M68881__) && !defined (sfp004)
  80.  
  81. #if defined (__M68881__) || defined (sfp004)
  82. # ifdef ERROR_CHECK    /* no error checking for now    */
  83. __asm("
  84. .text
  85. _funcname:
  86.     .ascii    \"csin\\0\"
  87.     .even
  88. ");    /* end asm    */
  89. # endif ERROR_CHECK
  90. #endif defined (__M68881__) || defined (sfp004)
  91.  
  92. #ifdef    __M68881__
  93. __asm("
  94. .text
  95.     .globl _csin
  96. _csin:
  97.     movel    a1,d0        | save a1 as return value
  98.     fmoved    sp@(4),fp0    | z.real
  99.     fcosx    fp0,fp1        | cos(z.real)
  100.     fsinx    fp0,fp0        | sin(z.real)
  101.  
  102.     fmoved    sp@(12),fp3    | z.imag
  103.     fcoshx    fp3,fp2        | cosh(z.imag)
  104.     fsinhx    fp3,fp3        | sinh(z.imag)
  105.     
  106.     fmulx    fp2,fp0        | result.real
  107.     fmoved    fp0,a1@        |
  108.     fmulx    fp3,fp1        | result.imag
  109.     fmoved    fp1,a1@(8)    |
  110. ");    /* end asm    */
  111. #endif    __M68881__
  112.  
  113. #ifdef    sfp004
  114. __asm("
  115. | double precision floating point stuff for Atari-gcc using the SFP004
  116. | developed with gas
  117. |
  118. | double precision complex sin
  119. |
  120. | M. Ritzert (mjr at dmzrzu71)
  121. |
  122. | 12.10.1990
  123. |
  124. | addresses of the 68881 data port. This choice is fastest when much data is
  125. | transferred between the two processors.
  126.  
  127. comm =     -6
  128. resp =    -16
  129. zahl =      0
  130.  
  131. | waiting loop ...
  132. |
  133. | wait:
  134. | ww:    cmpiw    #0x8900,a1@(resp)
  135. |     beq    ww
  136. | is coded directly by
  137. |    .long    0x0c688900, 0xfff067f8
  138. | and
  139. | www:    tst.b    a1@(resp)
  140. |    bmi.b    www
  141. | is coded by
  142. |    .word    0x4a68,0xfff0,0x6bfa        | test
  143.  
  144.     .text; .even
  145.     .globl _csin
  146. _csin:
  147.     movel    a1,d0                | save a1 as return value
  148.     lea    0xfffa50,a0            | fpu address
  149.  
  150.     movew    #0x5431,a0@(comm)        | sincos: sin -> fp0 
  151.     .long    0x0c688900, 0xfff067f8        |      cos -> fp1
  152.     movel    sp@(4), a0@            | load z.real
  153.     movel    sp@(8), a0@            | load z.real
  154.  
  155. |    fmoved    sp@(12),fp3            | z.imag to fp3
  156.     movew    #0x5580,a0@(comm)
  157.     .long    0x0c688900, 0xfff067f8
  158.     movel    sp@(12),a0@
  159.     movel    sp@(16),a0@
  160.  
  161. |    fcoshx    fp3,fp2                | cosh(z.imag)
  162.     movew    #0x0d19,a0@(comm)
  163.     .word    0x4a68,0xfff0,0x6bfa        | test
  164. |    fsinhx    fp3,fp3                | sinh(z.imag)
  165.     movew    #0x0d82,a0@(comm)
  166.     .word    0x4a68,0xfff0,0x6bfa        | test
  167. |    fmulx    fp2,fp0                | result.real
  168.     movew    #0x0823,a0@(comm)
  169.     .word    0x4a68,0xfff0,0x6bfa        | test
  170. |    fmoved    fp0,a1@                |
  171.     movew    #0x7400,a0@(comm)        | 
  172.     .long    0x0c688900, 0xfff067f8
  173.     movel    a0@,a1@
  174.     movel    a0@,a1@(4)
  175. |    fmulx    fp3,fp1                | result.imag
  176.     movew    #0x0ca3,a0@(comm)
  177.     .word    0x4a68,0xfff0,0x6bfa        | test
  178. |    fmoves    fp1,d1                |
  179.     movew    #0x7480,a0@(comm)        |
  180.     .long    0x0c688900, 0xfff067f8
  181.     movel    a0@,a1@(8)
  182.     movel    a0@,a1@(12)
  183. ");    /* end asm    */
  184. #endif    sfp004
  185.  
  186.  
  187. #if defined (__M68881__) || defined (sfp004)
  188. # ifdef ERROR_CHECK    /* no error checking for now    */
  189. __asm("
  190.     pea    _funcname
  191.     jmp    c_err_check
  192. ");    /* end asm    */
  193. # else  ERROR_CHECK
  194.  
  195. __asm("rts");
  196.  
  197. # endif ERROR_CHECK
  198. #endif defined (__M68881__) || defined (sfp004)
  199.