home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / hobby / palmoon / palmoon.EXE / s_sincos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-16  |  2.2 KB  |  81 lines

  1. // 15 August 1997, Rick Huebner:  Small changes made to adapt for MathLib
  2.  
  3. /* Compute sine and cosine of argument.
  4.    Copyright (C) 1997 Free Software Foundation, Inc.
  5.    This file is part of the GNU C Library.
  6.    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
  7.  
  8.    The GNU C Library is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU Library General Public License as
  10.    published by the Free Software Foundation; either version 2 of the
  11.    License, or (at your option) any later version.
  12.  
  13.    The GNU C Library is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    Library General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU Library General Public
  19.    License along with the GNU C Library; see the file COPYING.LIB.  If not,
  20.    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21.    Boston, MA 02111-1307, USA.  */
  22.  
  23. #include "math.h"
  24.  
  25. #include "math_private.h"
  26.  
  27.  
  28. void
  29. __sincos (double x, double *sinx, double *cosx)
  30. {
  31.   int32_t ix;
  32.  
  33.   /* High word of x. */
  34.   GET_HIGH_WORD (ix, x);
  35.  
  36.   /* |x| ~< pi/4 */
  37.   ix &= 0x7fffffff;
  38.   if (ix <= 0x3fe921fb)
  39.     {
  40.       *sinx = __kernel_sin (x, 0.0, 0);
  41.       *cosx = __kernel_cos (x, 0.0);
  42.     }
  43.   else if (ix>=0x7ff00000)
  44.     {
  45.       /* sin(Inf or NaN) is NaN */
  46.       *sinx = *cosx = x - x;
  47.     }
  48.   else
  49.     {
  50.       /* Argument reduction needed.  */
  51.       double y[2];
  52.       int n;
  53.  
  54.       n = __ieee754_rem_pio2 (x, y);
  55.       switch (n & 3)
  56.     {
  57.     case 0:
  58.       *sinx = __kernel_sin (y[0], y[1], 1);
  59.       *cosx = __kernel_cos (y[0], y[1]);
  60.       break;
  61.     case 1:
  62.       *sinx = __kernel_cos (y[0], y[1]);
  63.       *cosx = -__kernel_sin (y[0], y[1], 1);
  64.       break;
  65.     case 2:
  66.       *sinx = -__kernel_sin (y[0], y[1], 1);
  67.       *cosx = -__kernel_cos (y[0], y[1]);
  68.       break;
  69.     default:
  70.       *sinx = -__kernel_cos (y[0], y[1]);
  71.       *cosx = __kernel_sin (y[0], y[1], 1);
  72.       break;
  73.     }
  74.     }
  75. }
  76. weak_alias (__sincos, sincos)
  77. #ifdef NO_LONG_DOUBLE
  78. strong_alias (__sincos, __sincosl)
  79. weak_alias (__sincos, sincosl)
  80. #endif
  81.