|
Packit Service |
82fcde |
/* s_cosf.c -- float version of s_cos.c.
|
|
Packit Service |
82fcde |
Copyright (C) 2011-2018 Free Software Foundation, Inc.
|
|
Packit Service |
82fcde |
This file is part of the GNU C Library.
|
|
Packit Service |
82fcde |
Contributed by Adhemerval Zanella <azanella@br.ibm.com>, 2011
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
82fcde |
modify it under the terms of the GNU Library General Public License as
|
|
Packit Service |
82fcde |
published by the Free Software Foundation; either version 2 of the
|
|
Packit Service |
82fcde |
License, or (at your option) any later version.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
82fcde |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
82fcde |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
82fcde |
Library General Public License for more details.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
You should have received a copy of the GNU Library General Public
|
|
Packit Service |
82fcde |
License along with the GNU C Library; see the file COPYING.LIB. If
|
|
Packit Service |
82fcde |
not, see <http://www.gnu.org/licenses/>. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <errno.h>
|
|
Packit Service |
82fcde |
#include <math.h>
|
|
Packit Service |
82fcde |
#include <math_private.h>
|
|
Packit Service |
82fcde |
#include <libm-alias-float.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static const float pio4 = 7.8539801e-1;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
float
|
|
Packit Service |
82fcde |
__cosf (float x)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
float y[2], z = 0.0;
|
|
Packit Service |
82fcde |
float ix;
|
|
Packit Service |
82fcde |
int32_t n;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
ix = __builtin_fabsf (x);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* |x| ~< pi/4 */
|
|
Packit Service |
82fcde |
if (ix <= pio4)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
return __kernel_cosf (x, z);
|
|
Packit Service |
82fcde |
/* cos(Inf or NaN) is NaN */
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
else if (isnanf (ix))
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
return x - x;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
else if (isinff (ix))
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
__set_errno (EDOM);
|
|
Packit Service |
82fcde |
return x - x;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* argument reduction needed */
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
n = __ieee754_rem_pio2f (x, y);
|
|
Packit Service |
82fcde |
switch (n & 3)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
case 0:
|
|
Packit Service |
82fcde |
return __kernel_cosf (y[0], y[1]);
|
|
Packit Service |
82fcde |
case 1:
|
|
Packit Service |
82fcde |
return -__kernel_sinf (y[0], y[1], 1);
|
|
Packit Service |
82fcde |
case 2:
|
|
Packit Service |
82fcde |
return -__kernel_cosf (y[0], y[1]);
|
|
Packit Service |
82fcde |
default:
|
|
Packit Service |
82fcde |
return __kernel_sinf (y[0], y[1], 1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
libm_alias_float (__cos, cos)
|