Back to index

glibc  2.9
s_cexp.c
Go to the documentation of this file.
00001 /* Complex exponential function.  m68k fpu version
00002    Copyright (C) 1997, 1999 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <complex.h>
00022 #include <math.h>
00023 #include "mathimpl.h"
00024 
00025 #ifndef SUFF
00026 #define SUFF
00027 #endif
00028 #ifndef float_type
00029 #define float_type double
00030 #endif
00031 
00032 #define CONCATX(a,b) __CONCAT(a,b)
00033 #define s(name) CONCATX(name,SUFF)
00034 #define m81(func) __m81_u(s(func))
00035 
00036 __complex__ float_type
00037 s(__cexp) (__complex__ float_type x)
00038 {
00039   __complex__ float_type retval;
00040   unsigned long ix_cond;
00041 
00042   ix_cond = __m81_test (__imag__ x);
00043 
00044   if ((ix_cond & (__M81_COND_NAN|__M81_COND_INF)) == 0)
00045     {
00046       /* Imaginary part is finite.  */
00047       float_type exp_val = m81(__ieee754_exp) (__real__ x);
00048 
00049       __real__ retval = __imag__ retval = exp_val;
00050       if (m81(__finite) (exp_val))
00051        {
00052          float_type sin_ix, cos_ix;
00053          __asm ("fsincos%.x %2,%1:%0" : "=f" (sin_ix), "=f" (cos_ix)
00054                : "f" (__imag__ x));
00055          __real__ retval *= cos_ix;
00056          if (ix_cond & __M81_COND_ZERO)
00057            __imag__ retval = __imag__ x;
00058          else
00059            __imag__ retval *= sin_ix;
00060        }
00061       else
00062        {
00063          /* Compute the sign of the result.  */
00064          float_type remainder, pi_2;
00065          int quadrant;
00066 
00067          __asm ("fmovecr %#0,%0\n\tfscale%.w %#-1,%0" : "=f" (pi_2));
00068          __asm ("fmod%.x %2,%0\n\tfmove%.l %/fpsr,%1"
00069                : "=f" (remainder), "=dm" (quadrant)
00070                : "f" (pi_2), "0" (__imag__ x));
00071          quadrant = (quadrant >> 16) & 0x83;
00072          if (quadrant & 0x80)
00073            quadrant ^= 0x83;
00074          switch (quadrant)
00075            {
00076            default:
00077              break;
00078            case 1:
00079              __real__ retval = -__real__ retval;
00080              break;
00081            case 2:
00082              __real__ retval = -__real__ retval;
00083            case 3:
00084              __imag__ retval = -__imag__ retval;
00085              break;
00086            }
00087          if (ix_cond & __M81_COND_ZERO && !m81(__isnan) (exp_val))
00088            __imag__ retval = __imag__ x;
00089        }
00090     }
00091   else
00092     {
00093       unsigned long rx_cond = __m81_test (__real__ x);
00094 
00095       if (rx_cond & __M81_COND_INF)
00096        {
00097          /* Real part is infinite.  */
00098          if (rx_cond & __M81_COND_NEG)
00099            {
00100              __real__ retval = __imag__ retval = 0.0;
00101              if (ix_cond & __M81_COND_NEG)
00102               __imag__ retval = -__imag__ retval;
00103            }
00104          else
00105            {
00106              __real__ retval = __real__ x;
00107              __imag__ retval = __imag__ x - __imag__ x;
00108            }
00109        }
00110       else
00111        __real__ retval = __imag__ retval = __imag__ x - __imag__ x;
00112     }
00113 
00114   return retval;
00115 }
00116 #define weak_aliasx(a,b) weak_alias(a,b)
00117 weak_aliasx (s(__cexp), s(cexp))