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 / crcp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-19  |  2.1 KB  |  96 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. /*
  22.  *  FUNCTION
  23.  *
  24.  *    crcp   complex double precision reciprocal
  25.  *
  26.  *  KEY WORDS
  27.  *
  28.  *    crcp
  29.  *    complex functions
  30.  *    math libraries
  31.  *
  32.  *  DESCRIPTION
  33.  *
  34.  *    Computes double precision complex reciprocal of
  35.  *    a double precision complex argument.
  36.  *
  37.  *  USAGE
  38.  *
  39.  *    COMPLEX crcp (z)
  40.  *    COMPLEX z;
  41.  *
  42.  *  PROGRAMMER
  43.  *
  44.  *    Fred Fish
  45.  *    Tempe, Az 85281
  46.  *    (602) 966-8871
  47.  *
  48.  *  INTERNALS
  49.  *
  50.  *    Computes complex reciprocal of z = x + j y from:
  51.  *
  52.  *        1.    Compute denom = x*x + y*y
  53.  *
  54.  *        2.    If denom = 0.0 then flag error
  55.  *            and return MAX_POS_DBLF + j 0.0
  56.  *
  57.  *        3.    Else crcp(z) = (x/denom) + j (-y/denom)
  58.  *
  59.  */
  60.  
  61. #if defined (__M68881__) && !defined (_M68881)
  62. /*# define _M68881*/
  63. #endif
  64.  
  65. #include <stdio.h>
  66. #include <math.h>
  67. #include "pml.h"
  68.  
  69.  
  70.     double denom;
  71.     struct exception xcpt;
  72.  
  73. COMPLEX crcp (z)
  74. COMPLEX z;
  75. {
  76.     denom = (z.real * z.real) + (z.imag * z.imag);
  77.     if (denom == 0.0) {
  78.     xcpt.type = SING;
  79.     xcpt.name = "crcp";
  80.     xcpt.arg1 = denom;
  81.     if (!matherr (&xcpt)) {
  82.         fprintf (stderr, "%s: ZERO_CMPLX_DENOMINATOR \n", xcpt.name);
  83.         errno = ERANGE;
  84.         xcpt.retval = 0.0;    /* useless in this context */
  85.     }
  86.     if( z.real >= 0.0 )    z.real =  HUGE_VAL;
  87.     else            z.real = -HUGE_VAL;
  88.     if( z.imag  < 0.0 )    z.imag =  HUGE_VAL;
  89.     else            z.imag = -HUGE_VAL;
  90.     } else {
  91.     z.real /= denom;
  92.     z.imag /= -denom;
  93.     }
  94.     return (z);
  95. }
  96.