?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. /*-------------------------------------------------------------------------
  2.    sincoshf.c - Computes sinh or cosh of a 32-bit float as outlined in [1]
  3.  
  4.    Copyright (C) 2001, 2002, Jesus Calvino-Fraga, jesusc@ieee.org
  5.  
  6.    This library is free software; you can redistribute it and/or modify it
  7.    under the terms of the GNU General Public License as published by the
  8.    Free Software Foundation; either version 2, or (at your option) any
  9.    later version.
  10.  
  11.    This library is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this library; see the file COPYING. If not, write to the
  18.    Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
  19.    MA 02110-1301, USA.
  20.  
  21.    As a special exception, if you link this library with other files,
  22.    some of which are compiled with SDCC, to produce an executable,
  23.    this library does not by itself cause the resulting executable to
  24.    be covered by the GNU General Public License. This exception does
  25.    not however invalidate any other reasons why the executable file
  26.    might be covered by the GNU General Public License.
  27. -------------------------------------------------------------------------*/
  28.  
  29. /* [1] William James Cody and W.  M.  Waite.  _Software manual for the
  30.    elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */
  31.  
  32. /* Version 1.0 - Initial release */
  33.  
  34. #include <math.h>
  35. #include <errno.h>
  36. #include <stdbool.h>
  37.  
  38. #define P0 -0.713793159E+1
  39. #define P1 -0.190333999E+0
  40. #define Q0 -0.428277109E+2
  41. #define Q1  0.100000000E+1
  42.  
  43. #define P(z) (P1*z+P0)
  44. #define Q(z) (Q1*z+Q0)
  45.  
  46. #define K1 0.69316101074218750000E+0 /* ln(v)   */
  47. #define K2 0.24999308500451499336E+0 /* v**(-2) */
  48. #define K3 0.13830277879601902638E-4 /* v/2-1   */
  49.  
  50. //WMAX is defined as ln(HUGE_VALF)-ln(v)+0.69
  51. #define WMAX 44.93535952E+0
  52. //WBAR 0.35*(b+1)
  53. #define WBAR 1.05
  54. #define YBAR 9.0 /*Works for me*/
  55.  
  56. float sincoshf(float x, bool iscosh)
  57. {
  58.     float y, w, z;
  59.     bool sign;
  60.  
  61.     if (x<0.0) { y=-x; sign=1; }
  62.           else { y=x;  sign=0; }
  63.  
  64.     if ((y>1.0) || iscosh)
  65.     {
  66.         if(y>YBAR)
  67.         {
  68.             w=y-K1;
  69.             if (w>WMAX)
  70.             {
  71.                 errno=ERANGE;
  72.                 z=HUGE_VALF;
  73.             }
  74.             else
  75.             {
  76.                 z=expf(w);
  77.                 z+=K3*z;
  78.             }
  79.         }
  80.         else
  81.         {
  82.             z=expf(y);
  83.             w=1.0/z;
  84.             if(!iscosh) w=-w;
  85.             z=(z+w)*0.5;
  86.         }
  87.         if(sign) z=-z;
  88.     }
  89.     else
  90.     {
  91.         if (y<EPS)
  92.             z=x;
  93.         else
  94.         {
  95.             z=x*x;
  96.             z=x+x*z*P(z)/Q(z);
  97.         }
  98.     }
  99.     return z;
  100. }
  101.