added more math functions (complex ones)

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16392 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2006-02-14 13:34:43 +00:00
parent 162972f5f2
commit 5acbf1f50e
27 changed files with 2135 additions and 0 deletions

View File

@ -0,0 +1,41 @@
/* Return cosine of complex double value.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
__complex__ double
__cacos (__complex__ double x)
{
__complex__ double y;
__complex__ double res;
y = __casin (x);
__real__ res = (double) M_PI_2 - __real__ y;
__imag__ res = -__imag__ y;
return res;
}
weak_alias (__cacos, cacos)
#ifdef NO_LONG_DOUBLE
strong_alias (__cacos, __cacosl)
weak_alias (__cacos, cacosl)
#endif

View File

@ -0,0 +1,39 @@
/* Return cosine of complex float value.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
__complex__ float
__cacosf (__complex__ float x)
{
__complex__ float y;
__complex__ float res;
y = __casinf (x);
__real__ res = (float) M_PI_2 - __real__ y;
__imag__ res = -__imag__ y;
return res;
}
#ifndef __cacosf
weak_alias (__cacosf, cacosf)
#endif

View File

@ -0,0 +1,88 @@
/* Return arc hyperbole cosine for double value.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
__complex__ double
__cacosh (__complex__ double x)
{
__complex__ double res;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
{
if (icls == FP_INFINITE)
{
__real__ res = HUGE_VAL;
if (rcls == FP_NAN)
__imag__ res = __nan ("");
else
__imag__ res = __copysign ((rcls == FP_INFINITE
? (__real__ x < 0.0
? M_PI - M_PI_4 : M_PI_4)
: M_PI_2), __imag__ x);
}
else if (rcls == FP_INFINITE)
{
__real__ res = HUGE_VAL;
if (icls >= FP_ZERO)
__imag__ res = __copysign (signbit (__real__ x) ? M_PI : 0.0,
__imag__ x);
else
__imag__ res = __nan ("");
}
else
{
__real__ res = __nan ("");
__imag__ res = __nan ("");
}
}
else if (rcls == FP_ZERO && icls == FP_ZERO)
{
__real__ res = 0.0;
__imag__ res = __copysign (M_PI_2, __imag__ x);
}
else
{
__complex__ double y;
__real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) - 1.0;
__imag__ y = 2.0 * __real__ x * __imag__ x;
y = __csqrt (y);
__real__ y += __real__ x;
__imag__ y += __imag__ x;
res = __clog (y);
}
return res;
}
weak_alias (__cacosh, cacosh)
#ifdef NO_LONG_DOUBLE
strong_alias (__cacosh, __cacoshl)
weak_alias (__cacosh, cacoshl)
#endif

View File

@ -0,0 +1,101 @@
/* Return arc hyperbole cosine for float value.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
#include "math_private.h"
__complex__ float
__cacoshf (__complex__ float x)
{
__complex__ float res;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
{
if (icls == FP_INFINITE)
{
__real__ res = HUGE_VALF;
if (rcls == FP_NAN)
__imag__ res = __nanf ("");
else
__imag__ res = __copysignf ((rcls == FP_INFINITE
? (__real__ x < 0.0
? M_PI - M_PI_4 : M_PI_4)
: M_PI_2), __imag__ x);
}
else if (rcls == FP_INFINITE)
{
__real__ res = HUGE_VALF;
if (icls >= FP_ZERO)
__imag__ res = __copysignf (signbit (__real__ x) ? M_PI : 0.0,
__imag__ x);
else
__imag__ res = __nanf ("");
}
else
{
__real__ res = __nanf ("");
__imag__ res = __nanf ("");
}
}
else if (rcls == FP_ZERO && icls == FP_ZERO)
{
__real__ res = 0.0;
__imag__ res = __copysignf (M_PI_2, __imag__ x);
}
else
{
#if 1
__complex__ float y;
__real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) - 1.0;
__imag__ y = 2.0 * __real__ x * __imag__ x;
y = __csqrtf (y);
__real__ y += __real__ x;
__imag__ y += __imag__ x;
res = __clogf (y);
#else
float re2 = __real__ x * __real__ x;
float im2 = __imag__ x * __imag__ x;
float sq = re2 - im2 - 1.0;
float ro = __ieee754_sqrtf (sq * sq + 4 * re2 * im2);
float a = __ieee754_sqrtf ((sq + ro) / 2.0);
float b = __ieee754_sqrtf ((-sq + ro) / 2.0);
__real__ res = 0.5 * __ieee754_logf (re2 + __real__ x * 2 * a
+ im2 + __imag__ x * 2 * b
+ ro);
__imag__ res = __ieee754_atan2f (__imag__ x + b, __real__ x + a);
#endif
}
return res;
}
#ifndef __cacoshf
weak_alias (__cacoshf, cacoshf)
#endif

View File

@ -0,0 +1,84 @@
/* Return arc hyperbole cosine for long double value.
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
__complex__ long double
__cacoshl (__complex__ long double x)
{
__complex__ long double res;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
{
if (icls == FP_INFINITE)
{
__real__ res = HUGE_VALL;
if (rcls == FP_NAN)
__imag__ res = __nanl ("");
else
__imag__ res = __copysignl ((rcls == FP_INFINITE
? (__real__ x < 0.0
? M_PIl - M_PI_4l : M_PI_4l)
: M_PI_2l), __imag__ x);
}
else if (rcls == FP_INFINITE)
{
__real__ res = HUGE_VALL;
if (icls >= FP_ZERO)
__imag__ res = __copysignl (signbit (__real__ x) ? M_PIl : 0.0,
__imag__ x);
else
__imag__ res = __nanl ("");
}
else
{
__real__ res = __nanl ("");
__imag__ res = __nanl ("");
}
}
else if (rcls == FP_ZERO && icls == FP_ZERO)
{
__real__ res = 0.0;
__imag__ res = __copysignl (M_PI_2l, __imag__ x);
}
else
{
__complex__ long double y;
__real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) - 1.0;
__imag__ y = 2.0 * __real__ x * __imag__ x;
y = __csqrtl (y);
__real__ y += __real__ x;
__imag__ y += __imag__ x;
res = __clogl (y);
}
return res;
}
weak_alias (__cacoshl, cacoshl)

View File

@ -0,0 +1,37 @@
/* Return cosine of complex long double value.
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
__complex__ long double
__cacosl (__complex__ long double x)
{
__complex__ long double y;
__complex__ long double res;
y = __casinl (x);
__real__ res = M_PI_2l - __real__ y;
__imag__ res = -__imag__ y;
return res;
}
weak_alias (__cacosl, cacosl)

View File

@ -0,0 +1,66 @@
/* Return arc sine of complex double value.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
__complex__ double
__casin (__complex__ double x)
{
__complex__ double res;
if (isnan (__real__ x) || isnan (__imag__ x))
{
if (__real__ x == 0.0)
{
res = x;
}
else if (__isinf (__real__ x) || __isinf (__imag__ x))
{
__real__ res = __nan ("");
__imag__ res = __copysign (HUGE_VAL, __imag__ x);
}
else
{
__real__ res = __nan ("");
__imag__ res = __nan ("");
}
}
else
{
__complex__ double y;
__real__ y = -__imag__ x;
__imag__ y = __real__ x;
y = __casinh (y);
__real__ res = __imag__ y;
__imag__ res = -__real__ y;
}
return res;
}
weak_alias (__casin, casin)
#ifdef NO_LONG_DOUBLE
strong_alias (__casin, __casinl)
weak_alias (__casin, casinl)
#endif

View File

@ -0,0 +1,64 @@
/* Return arc sine of complex float value.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
__complex__ float
__casinf (__complex__ float x)
{
__complex__ float res;
if (isnan (__real__ x) || isnan (__imag__ x))
{
if (__real__ x == 0.0)
{
res = x;
}
else if (__isinff (__real__ x) || __isinff (__imag__ x))
{
__real__ res = __nanf ("");
__imag__ res = __copysignf (HUGE_VALF, __imag__ x);
}
else
{
__real__ res = __nanf ("");
__imag__ res = __nanf ("");
}
}
else
{
__complex__ float y;
__real__ y = -__imag__ x;
__imag__ y = __real__ x;
y = __casinhf (y);
__real__ res = __imag__ y;
__imag__ res = -__real__ y;
}
return res;
}
#ifndef __casinf
weak_alias (__casinf, casinf)
#endif

View File

@ -0,0 +1,84 @@
/* Return arc hyperbole sine for double value.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
__complex__ double
__casinh (__complex__ double x)
{
__complex__ double res;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
{
if (icls == FP_INFINITE)
{
__real__ res = __copysign (HUGE_VAL, __real__ x);
if (rcls == FP_NAN)
__imag__ res = __nan ("");
else
__imag__ res = __copysign (rcls >= FP_ZERO ? M_PI_2 : M_PI_4,
__imag__ x);
}
else if (rcls <= FP_INFINITE)
{
__real__ res = __real__ x;
if ((rcls == FP_INFINITE && icls >= FP_ZERO)
|| (rcls == FP_NAN && icls == FP_ZERO))
__imag__ res = __copysign (0.0, __imag__ x);
else
__imag__ res = __nan ("");
}
else
{
__real__ res = __nan ("");
__imag__ res = __nan ("");
}
}
else if (rcls == FP_ZERO && icls == FP_ZERO)
{
res = x;
}
else
{
__complex__ double y;
__real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) + 1.0;
__imag__ y = 2.0 * __real__ x * __imag__ x;
y = __csqrt (y);
__real__ y += __real__ x;
__imag__ y += __imag__ x;
res = __clog (y);
}
return res;
}
weak_alias (__casinh, casinh)
#ifdef NO_LONG_DOUBLE
strong_alias (__casinh, __casinhl)
weak_alias (__casinh, casinhl)
#endif

View File

@ -0,0 +1,82 @@
/* Return arc hyperbole sine for float value.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
__complex__ float
__casinhf (__complex__ float x)
{
__complex__ float res;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
{
if (icls == FP_INFINITE)
{
__real__ res = __copysignf (HUGE_VALF, __real__ x);
if (rcls == FP_NAN)
__imag__ res = __nanf ("");
else
__imag__ res = __copysignf (rcls >= FP_ZERO ? M_PI_2 : M_PI_4,
__imag__ x);
}
else if (rcls <= FP_INFINITE)
{
__real__ res = __real__ x;
if ((rcls == FP_INFINITE && icls >= FP_ZERO)
|| (rcls == FP_NAN && icls == FP_ZERO))
__imag__ res = __copysignf (0.0, __imag__ x);
else
__imag__ res = __nanf ("");
}
else
{
__real__ res = __nanf ("");
__imag__ res = __nanf ("");
}
}
else if (rcls == FP_ZERO && icls == FP_ZERO)
{
res = x;
}
else
{
__complex__ float y;
__real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) + 1.0;
__imag__ y = 2.0 * __real__ x * __imag__ x;
y = __csqrtf (y);
__real__ y += __real__ x;
__imag__ y += __imag__ x;
res = __clogf (y);
}
return res;
}
#ifndef __casinhf
weak_alias (__casinhf, casinhf)
#endif

View File

@ -0,0 +1,80 @@
/* Return arc hyperbole sine for long double value.
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
__complex__ long double
__casinhl (__complex__ long double x)
{
__complex__ long double res;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
{
if (icls == FP_INFINITE)
{
__real__ res = __copysignl (HUGE_VALL, __real__ x);
if (rcls == FP_NAN)
__imag__ res = __nanl ("");
else
__imag__ res = __copysignl (rcls >= FP_ZERO ? M_PI_2l : M_PI_4l,
__imag__ x);
}
else if (rcls <= FP_INFINITE)
{
__real__ res = __real__ x;
if ((rcls == FP_INFINITE && icls >= FP_ZERO)
|| (rcls == FP_NAN && icls == FP_ZERO))
__imag__ res = __copysignl (0.0, __imag__ x);
else
__imag__ res = __nanl ("");
}
else
{
__real__ res = __nanl ("");
__imag__ res = __nanl ("");
}
}
else if (rcls == FP_ZERO && icls == FP_ZERO)
{
res = x;
}
else
{
__complex__ long double y;
__real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) + 1.0;
__imag__ y = 2.0 * __real__ x * __imag__ x;
y = __csqrtl (y);
__real__ y += __real__ x;
__imag__ y += __imag__ x;
res = __clogl (y);
}
return res;
}
weak_alias (__casinhl, casinhl)

View File

@ -0,0 +1,62 @@
/* Return arc sine of complex long double value.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
__complex__ long double
__casinl (__complex__ long double x)
{
__complex__ long double res;
if (isnan (__real__ x) || isnan (__imag__ x))
{
if (__real__ x == 0.0)
{
res = x;
}
else if (__isinfl (__real__ x) || __isinfl (__imag__ x))
{
__real__ res = __nanl ("");
__imag__ res = __copysignl (HUGE_VALL, __imag__ x);
}
else
{
__real__ res = __nanl ("");
__imag__ res = __nanl ("");
}
}
else
{
__complex__ long double y;
__real__ y = -__imag__ x;
__imag__ y = __real__ x;
y = __casinhl (y);
__real__ res = __imag__ y;
__imag__ res = -__real__ y;
}
return res;
}
weak_alias (__casinl, casinl)

View File

@ -0,0 +1,89 @@
/* Return arc tangent of complex double value.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
#include "math_private.h"
__complex__ double
__catan (__complex__ double x)
{
__complex__ double res;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
{
if (rcls == FP_INFINITE)
{
__real__ res = __copysign (M_PI_2, __real__ x);
__imag__ res = __copysign (0.0, __imag__ x);
}
else if (icls == FP_INFINITE)
{
if (rcls >= FP_ZERO)
__real__ res = __copysign (M_PI_2, __real__ x);
else
__real__ res = __nan ("");
__imag__ res = __copysign (0.0, __imag__ x);
}
else if (icls == FP_ZERO || icls == FP_INFINITE)
{
__real__ res = __nan ("");
__imag__ res = __copysign (0.0, __imag__ x);
}
else
{
__real__ res = __nan ("");
__imag__ res = __nan ("");
}
}
else if (rcls == FP_ZERO && icls == FP_ZERO)
{
res = x;
}
else
{
double r2, num, den;
r2 = __real__ x * __real__ x;
den = 1 - r2 - __imag__ x * __imag__ x;
__real__ res = 0.5 * __ieee754_atan2 (2.0 * __real__ x, den);
num = __imag__ x + 1.0;
num = r2 + num * num;
den = __imag__ x - 1.0;
den = r2 + den * den;
__imag__ res = 0.25 * __ieee754_log (num / den);
}
return res;
}
weak_alias (__catan, catan)
#ifdef NO_LONG_DOUBLE
strong_alias (__catan, __catanl)
weak_alias (__catan, catanl)
#endif

View File

@ -0,0 +1,87 @@
/* Return arc tangent of complex float value.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
#include "math_private.h"
__complex__ float
__catanf (__complex__ float x)
{
__complex__ float res;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
{
if (rcls == FP_INFINITE)
{
__real__ res = __copysignf (M_PI_2, __real__ x);
__imag__ res = __copysignf (0.0, __imag__ x);
}
else if (icls == FP_INFINITE)
{
if (rcls >= FP_ZERO)
__real__ res = __copysignf (M_PI_2, __real__ x);
else
__real__ res = __nanf ("");
__imag__ res = __copysignf (0.0, __imag__ x);
}
else if (icls == FP_ZERO || icls == FP_INFINITE)
{
__real__ res = __nanf ("");
__imag__ res = __copysignf (0.0, __imag__ x);
}
else
{
__real__ res = __nanf ("");
__imag__ res = __nanf ("");
}
}
else if (rcls == FP_ZERO && icls == FP_ZERO)
{
res = x;
}
else
{
float r2, num, den;
r2 = __real__ x * __real__ x;
den = 1 - r2 - __imag__ x * __imag__ x;
__real__ res = 0.5 * __ieee754_atan2f (2.0 * __real__ x, den);
num = __imag__ x + 1.0;
num = r2 + num * num;
den = __imag__ x - 1.0;
den = r2 + den * den;
__imag__ res = 0.25 * __ieee754_logf (num / den);
}
return res;
}
#ifndef __catanf
weak_alias (__catanf, catanf)
#endif

View File

@ -0,0 +1,84 @@
/* Return arc hyperbole tangent for double value.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
#include "math_private.h"
__complex__ double
__catanh (__complex__ double x)
{
__complex__ double res;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
{
if (icls == FP_INFINITE)
{
__real__ res = __copysign (0.0, __real__ x);
__imag__ res = __copysign (M_PI_2, __imag__ x);
}
else if (rcls == FP_INFINITE || rcls == FP_ZERO)
{
__real__ res = __copysign (0.0, __real__ x);
if (icls >= FP_ZERO)
__imag__ res = __copysign (M_PI_2, __imag__ x);
else
__imag__ res = __nan ("");
}
else
{
__real__ res = __nan ("");
__imag__ res = __nan ("");
}
}
else if (rcls == FP_ZERO && icls == FP_ZERO)
{
res = x;
}
else
{
double i2, num, den;
i2 = __imag__ x * __imag__ x;
num = 1.0 + __real__ x;
num = i2 + num * num;
den = 1.0 - __real__ x;
den = i2 + den * den;
__real__ res = 0.25 * (__ieee754_log (num) - __ieee754_log (den));
den = 1 - __real__ x * __real__ x - i2;
__imag__ res = 0.5 * __ieee754_atan2 (2.0 * __imag__ x, den);
}
return res;
}
weak_alias (__catanh, catanh)
#ifdef NO_LONG_DOUBLE
strong_alias (__catanh, __catanhl)
weak_alias (__catanh, catanhl)
#endif

View File

@ -0,0 +1,82 @@
/* Return arc hyperbole tangent for float value.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
#include "math_private.h"
__complex__ float
__catanhf (__complex__ float x)
{
__complex__ float res;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
{
if (icls == FP_INFINITE)
{
__real__ res = __copysignf (0.0, __real__ x);
__imag__ res = __copysignf (M_PI_2, __imag__ x);
}
else if (rcls == FP_INFINITE || rcls == FP_ZERO)
{
__real__ res = __copysignf (0.0, __real__ x);
if (icls >= FP_ZERO)
__imag__ res = __copysignf (M_PI_2, __imag__ x);
else
__imag__ res = __nanf ("");
}
else
{
__real__ res = __nanf ("");
__imag__ res = __nanf ("");
}
}
else if (rcls == FP_ZERO && icls == FP_ZERO)
{
res = x;
}
else
{
float i2, num, den;
i2 = __imag__ x * __imag__ x;
num = 1.0 + __real__ x;
num = i2 + num * num;
den = 1.0 - __real__ x;
den = i2 + den * den;
__real__ res = 0.25 * (__ieee754_logf (num) - __ieee754_logf (den));
den = 1 - __real__ x * __real__ x - i2;
__imag__ res = 0.5 * __ieee754_atan2f (2.0 * __imag__ x, den);
}
return res;
}
#ifndef __catanhf
weak_alias (__catanhf, catanhf)
#endif

View File

@ -0,0 +1,80 @@
/* Return arc hyperbole tangent for long double value.
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
#include "math_private.h"
__complex__ long double
__catanhl (__complex__ long double x)
{
__complex__ long double res;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
{
if (icls == FP_INFINITE)
{
__real__ res = __copysignl (0.0, __real__ x);
__imag__ res = __copysignl (M_PI_2l, __imag__ x);
}
else if (rcls == FP_INFINITE || rcls == FP_ZERO)
{
__real__ res = __copysignl (0.0, __real__ x);
if (icls >= FP_ZERO)
__imag__ res = __copysignl (M_PI_2l, __imag__ x);
else
__imag__ res = __nanl ("");
}
else
{
__real__ res = __nanl ("");
__imag__ res = __nanl ("");
}
}
else if (rcls == FP_ZERO && icls == FP_ZERO)
{
res = x;
}
else
{
long double i2, num, den;
i2 = __imag__ x * __imag__ x;
num = 1.0 + __real__ x;
num = i2 + num * num;
den = 1.0 - __real__ x;
den = i2 + den * den;
__real__ res = 0.25 * (__ieee754_logl (num) - __ieee754_logl (den));
den = 1 - __real__ x * __real__ x - i2;
__imag__ res = 0.5 * __ieee754_atan2l (2.0 * __imag__ x, den);
}
return res;
}
weak_alias (__catanhl, catanhl)

View File

@ -0,0 +1,85 @@
/* Return arc tangent of complex long double value.
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
#include "math_private.h"
__complex__ long double
__catanl (__complex__ long double x)
{
__complex__ long double res;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
{
if (rcls == FP_INFINITE)
{
__real__ res = __copysignl (M_PI_2l, __real__ x);
__imag__ res = __copysignl (0.0, __imag__ x);
}
else if (icls == FP_INFINITE)
{
if (rcls >= FP_ZERO)
__real__ res = __copysignl (M_PI_2l, __real__ x);
else
__real__ res = __nanl ("");
__imag__ res = __copysignl (0.0, __imag__ x);
}
else if (icls == FP_ZERO || icls == FP_INFINITE)
{
__real__ res = __nanl ("");
__imag__ res = __copysignl (0.0, __imag__ x);
}
else
{
__real__ res = __nanl ("");
__imag__ res = __nanl ("");
}
}
else if (rcls == FP_ZERO && icls == FP_ZERO)
{
res = x;
}
else
{
long double r2, num, den;
r2 = __real__ x * __real__ x;
den = 1 - r2 - __imag__ x * __imag__ x;
__real__ res = 0.5 * __ieee754_atan2l (2.0 * __real__ x, den);
num = __imag__ x + 1.0;
num = r2 + num * num;
den = __imag__ x - 1.0;
den = r2 + den * den;
__imag__ res = 0.25 * __ieee754_logl (num / den);
}
return res;
}
weak_alias (__catanl, catanl)

View File

@ -0,0 +1,65 @@
/* Compute complex natural logarithm.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
#include "math_private.h"
__complex__ double
__clog (__complex__ double x)
{
__complex__ double result;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls == FP_ZERO && icls == FP_ZERO)
{
/* Real and imaginary part are 0.0. */
__imag__ result = signbit (__real__ x) ? M_PI : 0.0;
__imag__ result = __copysign (__imag__ result, __imag__ x);
/* Yes, the following line raises an exception. */
__real__ result = -1.0 / fabs (__real__ x);
}
else if (rcls != FP_NAN && icls != FP_NAN)
{
/* Neither real nor imaginary part is NaN. */
__real__ result = __ieee754_log (__ieee754_hypot (__real__ x,
__imag__ x));
__imag__ result = __ieee754_atan2 (__imag__ x, __real__ x);
}
else
{
__imag__ result = __nan ("");
if (rcls == FP_INFINITE || icls == FP_INFINITE)
/* Real or imaginary part is infinite. */
__real__ result = HUGE_VAL;
else
__real__ result = __nan ("");
}
return result;
}
weak_alias (__clog, clog)
#ifdef NO_LONG_DOUBLE
strong_alias (__clog, __clogl)
weak_alias (__clog, clogl)
#endif

View File

@ -0,0 +1,63 @@
/* Compute complex natural logarithm.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
#include "math_private.h"
__complex__ float
__clogf (__complex__ float x)
{
__complex__ float result;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls == FP_ZERO && icls == FP_ZERO)
{
/* Real and imaginary part are 0.0. */
__imag__ result = signbit (__real__ x) ? M_PI : 0.0;
__imag__ result = __copysignf (__imag__ result, __imag__ x);
/* Yes, the following line raises an exception. */
__real__ result = -1.0 / fabsf (__real__ x);
}
else if (rcls != FP_NAN && icls != FP_NAN)
{
/* Neither real nor imaginary part is NaN. */
__real__ result = __ieee754_logf (__ieee754_hypotf (__real__ x,
__imag__ x));
__imag__ result = __ieee754_atan2f (__imag__ x, __real__ x);
}
else
{
__imag__ result = __nanf ("");
if (rcls == FP_INFINITE || icls == FP_INFINITE)
/* Real or imaginary part is infinite. */
__real__ result = HUGE_VALF;
else
__real__ result = __nanf ("");
}
return result;
}
#ifndef __clogf
weak_alias (__clogf, clogf)
#endif

View File

@ -0,0 +1,61 @@
/* Compute complex natural logarithm.
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
#include "math_private.h"
__complex__ long double
__clogl (__complex__ long double x)
{
__complex__ long double result;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls == FP_ZERO && icls == FP_ZERO)
{
/* Real and imaginary part are 0.0. */
__imag__ result = signbit (__real__ x) ? M_PIl : 0.0;
__imag__ result = __copysignl (__imag__ result, __imag__ x);
/* Yes, the following line raises an exception. */
__real__ result = -1.0 / fabsl (__real__ x);
}
else if (rcls != FP_NAN && icls != FP_NAN)
{
/* Neither real nor imaginary part is NaN. */
__real__ result = __ieee754_logl (__ieee754_hypotl (__real__ x,
__imag__ x));
__imag__ result = __ieee754_atan2l (__imag__ x, __real__ x);
}
else
{
__imag__ result = __nanl ("");
if (rcls == FP_INFINITE || icls == FP_INFINITE)
/* Real or imaginary part is infinite. */
__real__ result = HUGE_VALL;
else
__real__ result = __nanl ("");
}
return result;
}
weak_alias (__clogl, clogl)

View File

@ -0,0 +1,114 @@
/* Complex square root of double value.
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Based on an algorithm by Stephen L. Moshier <moshier@world.std.com>.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
#include "math_private.h"
__complex__ double
__csqrt (__complex__ double x)
{
__complex__ double res;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
{
if (icls == FP_INFINITE)
{
__real__ res = HUGE_VAL;
__imag__ res = __imag__ x;
}
else if (rcls == FP_INFINITE)
{
if (__real__ x < 0.0)
{
__real__ res = icls == FP_NAN ? __nan ("") : 0;
__imag__ res = __copysign (HUGE_VAL, __imag__ x);
}
else
{
__real__ res = __real__ x;
__imag__ res = (icls == FP_NAN
? __nan ("") : __copysign (0.0, __imag__ x));
}
}
else
{
__real__ res = __nan ("");
__imag__ res = __nan ("");
}
}
else
{
if (icls == FP_ZERO)
{
if (__real__ x < 0.0)
{
__real__ res = 0.0;
__imag__ res = __copysign (__ieee754_sqrt (-__real__ x),
__imag__ x);
}
else
{
__real__ res = fabs (__ieee754_sqrt (__real__ x));
__imag__ res = __copysign (0.0, __imag__ x);
}
}
else if (rcls == FP_ZERO)
{
double r = __ieee754_sqrt (0.5 * fabs (__imag__ x));
__real__ res = __copysign (r, __imag__ x);
__imag__ res = r;
}
else
{
double d, r, s;
d = __ieee754_hypot (__real__ x, __imag__ x);
/* Use the identity 2 Re res Im res = Im x
to avoid cancellation error in d +/- Re x. */
if (__real__ x > 0)
{
r = __ieee754_sqrt (0.5 * d + 0.5 * __real__ x);
s = (0.5 * __imag__ x) / r;
}
else
{
s = __ieee754_sqrt (0.5 * d - 0.5 * __real__ x);
r = fabs ((0.5 * __imag__ x) / s);
}
__real__ res = r;
__imag__ res = __copysign (s, __imag__ x);
}
}
return res;
}
weak_alias (__csqrt, csqrt)
#ifdef NO_LONG_DOUBLE
strong_alias (__csqrt, __csqrtl)
weak_alias (__csqrt, csqrtl)
#endif

View File

@ -0,0 +1,112 @@
/* Complex square root of float value.
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Based on an algorithm by Stephen L. Moshier <moshier@world.std.com>.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
#include "math_private.h"
__complex__ float
__csqrtf (__complex__ float x)
{
__complex__ float res;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
{
if (icls == FP_INFINITE)
{
__real__ res = HUGE_VALF;
__imag__ res = __imag__ x;
}
else if (rcls == FP_INFINITE)
{
if (__real__ x < 0.0)
{
__real__ res = icls == FP_NAN ? __nanf ("") : 0;
__imag__ res = __copysignf (HUGE_VALF, __imag__ x);
}
else
{
__real__ res = __real__ x;
__imag__ res = (icls == FP_NAN
? __nanf ("") : __copysignf (0.0, __imag__ x));
}
}
else
{
__real__ res = __nanf ("");
__imag__ res = __nanf ("");
}
}
else
{
if (icls == FP_ZERO)
{
if (__real__ x < 0.0)
{
__real__ res = 0.0;
__imag__ res = __copysignf (__ieee754_sqrtf (-__real__ x),
__imag__ x);
}
else
{
__real__ res = fabsf (__ieee754_sqrtf (__real__ x));
__imag__ res = __copysignf (0.0, __imag__ x);
}
}
else if (rcls == FP_ZERO)
{
float r = __ieee754_sqrtf (0.5 * fabsf (__imag__ x));
__real__ res = __copysignf (r, __imag__ x);
__imag__ res = r;
}
else
{
float d, r, s;
d = __ieee754_hypotf (__real__ x, __imag__ x);
/* Use the identity 2 Re res Im res = Im x
to avoid cancellation error in d +/- Re x. */
if (__real__ x > 0)
{
r = __ieee754_sqrtf (0.5f * d + 0.5f * __real__ x);
s = (0.5f * __imag__ x) / r;
}
else
{
s = __ieee754_sqrtf (0.5f * d - 0.5f * __real__ x);
r = fabsf ((0.5f * __imag__ x) / s);
}
__real__ res = r;
__imag__ res = __copysignf (s, __imag__ x);
}
}
return res;
}
#ifndef __csqrtf
weak_alias (__csqrtf, csqrtf)
#endif

View File

@ -0,0 +1,110 @@
/* Complex square root of long double value.
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Based on an algorithm by Stephen L. Moshier <moshier@world.std.com>.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <complex.h>
#include <math.h>
#include "math_private.h"
__complex__ long double
__csqrtl (__complex__ long double x)
{
__complex__ long double res;
int rcls = fpclassify (__real__ x);
int icls = fpclassify (__imag__ x);
if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
{
if (icls == FP_INFINITE)
{
__real__ res = HUGE_VALL;
__imag__ res = __imag__ x;
}
else if (rcls == FP_INFINITE)
{
if (__real__ x < 0.0)
{
__real__ res = icls == FP_NAN ? __nanl ("") : 0;
__imag__ res = __copysignl (HUGE_VALL, __imag__ x);
}
else
{
__real__ res = __real__ x;
__imag__ res = (icls == FP_NAN
? __nanl ("") : __copysignl (0.0, __imag__ x));
}
}
else
{
__real__ res = __nanl ("");
__imag__ res = __nanl ("");
}
}
else
{
if (icls == FP_ZERO)
{
if (__real__ x < 0.0)
{
__real__ res = 0.0;
__imag__ res = __copysignl (__ieee754_sqrtl (-__real__ x),
__imag__ x);
}
else
{
__real__ res = fabsl (__ieee754_sqrtl (__real__ x));
__imag__ res = __copysignl (0.0, __imag__ x);
}
}
else if (rcls == FP_ZERO)
{
long double r = __ieee754_sqrtl (0.5 * fabsl (__imag__ x));
__real__ res = __copysignl (r, __imag__ x);
__imag__ res = r;
}
else
{
long double d, r, s;
d = __ieee754_hypotl (__real__ x, __imag__ x);
/* Use the identity 2 Re res Im res = Im x
to avoid cancellation error in d +/- Re x. */
if (__real__ x > 0)
{
r = __ieee754_sqrtl (0.5L * d + 0.5L * __real__ x);
s = (0.5L * __imag__ x) / r;
}
else
{
s = __ieee754_sqrtl (0.5L * d - 0.5L * __real__ x);
r = fabsl ((0.5L * __imag__ x) / s);
}
__real__ res = r;
__imag__ res = __copysignl (s, __imag__ x);
}
}
return res;
}
weak_alias (__csqrtl, csqrtl)

View File

@ -3,6 +3,7 @@ SubDir HAIKU_TOP src system libroot posix glibc arch x86 ;
SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc include arch $(TARGET_ARCH) ;
SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc include arch generic ;
SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc include ;
SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc libio ;
SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc stdlib ;
SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc math ;
SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ;
@ -30,12 +31,21 @@ local genericSources =
k_cos.c k_cosf.c
k_sin.c k_sinf.c
k_tan.c k_tanf.c
s_cacos.c s_cacosf.c
s_cacosh.c s_cacoshf.c
s_casin.c s_casinf.c
s_casinh.c s_casinhf.c
s_catan.c s_catanf.c
s_catanh.c s_catanhf.c
s_clog.c s_clogf.c #s_clogl.c
s_csqrt.c s_csqrtf.c #s_csqrtl.c
s_erf.c s_erff.c # s_erfl.c
s_fpclassify.c s_fpclassifyf.c # s_fpclassifyl.c
s_isinf.c s_isinff.c
s_isnan.c s_isnanf.c
s_ldexp.c s_ldexpf.c #s_ldexpl.c
s_modf.c s_modff.c # s_modfl.c
s_nan.c s_nanf.c
s_signbit.c s_signbitl.c
s_round.c s_roundf.c # s_roundl.c
s_signgam.c

View File

@ -0,0 +1,158 @@
/* Prototype declarations for complex math functions;
helper file for <complex.h>.
Copyright (C) 1997, 1998, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
/* NOTE: Because of the special way this file is used by <complex.h>, this
file must NOT be protected from multiple inclusion as header files
usually are.
This file provides prototype declarations for the math functions.
Most functions are declared using the macro:
__MATHCALL (NAME, (ARGS...));
This means there is a function `NAME' returning `double' and a function
`NAMEf' returning `float'. Each place `_Mdouble_' appears in the
prototype, that is actually `double' in the prototype for `NAME' and
`float' in the prototype for `NAMEf'. Reentrant variant functions are
called `NAME_r' and `NAMEf_r'.
Functions returning other types like `int' are declared using the macro:
__MATHDECL (TYPE, NAME, (ARGS...));
This is just like __MATHCALL but for a function returning `TYPE'
instead of `_Mdouble_'. In all of these cases, there is still
both a `NAME' and a `NAMEf' that takes `float' arguments. */
#ifndef _COMPLEX_H
#error "Never use <bits/cmathcalls.h> directly; include <complex.h> instead."
#endif
#define _Mdouble_complex_ _Mdouble_ _Complex
/* Trigonometric functions. */
/* Arc cosine of Z. */
__MATHCALL (cacos, (_Mdouble_complex_ __z));
/* Arc sine of Z. */
__MATHCALL (casin, (_Mdouble_complex_ __z));
/* Arc tangent of Z. */
__MATHCALL (catan, (_Mdouble_complex_ __z));
/* Cosine of Z. */
__MATHCALL (ccos, (_Mdouble_complex_ __z));
/* Sine of Z. */
__MATHCALL (csin, (_Mdouble_complex_ __z));
/* Tangent of Z. */
__MATHCALL (ctan, (_Mdouble_complex_ __z));
/* Hyperbolic functions. */
/* Hyperbolic arc cosine of Z. */
__MATHCALL (cacosh, (_Mdouble_complex_ __z));
/* Hyperbolic arc sine of Z. */
__MATHCALL (casinh, (_Mdouble_complex_ __z));
/* Hyperbolic arc tangent of Z. */
__MATHCALL (catanh, (_Mdouble_complex_ __z));
/* Hyperbolic cosine of Z. */
__MATHCALL (ccosh, (_Mdouble_complex_ __z));
/* Hyperbolic sine of Z. */
__MATHCALL (csinh, (_Mdouble_complex_ __z));
/* Hyperbolic tangent of Z. */
__MATHCALL (ctanh, (_Mdouble_complex_ __z));
/* Exponential and logarithmic functions. */
/* Exponential function of Z. */
__MATHCALL (cexp, (_Mdouble_complex_ __z));
/* Natural logarithm of Z. */
__MATHCALL (clog, (_Mdouble_complex_ __z));
#ifdef __USE_GNU
/* The base 10 logarithm is not defined by the standard but to implement
the standard C++ library it is handy. */
__MATHCALL (clog10, (_Mdouble_complex_ __z));
#endif
/* Power functions. */
/* Return X to the Y power. */
__MATHCALL (cpow, (_Mdouble_complex_ __x, _Mdouble_complex_ __y));
/* Return the square root of Z. */
__MATHCALL (csqrt, (_Mdouble_complex_ __z));
/* Absolute value, conjugates, and projection. */
/* Absolute value of Z. */
__MATHDECL (_Mdouble_,cabs, (_Mdouble_complex_ __z));
/* Argument value of Z. */
__MATHDECL (_Mdouble_,carg, (_Mdouble_complex_ __z));
/* Complex conjugate of Z. */
__MATHCALL (conj, (_Mdouble_complex_ __z));
/* Projection of Z onto the Riemann sphere. */
__MATHCALL (cproj, (_Mdouble_complex_ __z));
/* Decomposing complex values. */
/* Imaginary part of Z. */
__MATHDECL (_Mdouble_,cimag, (_Mdouble_complex_ __z));
/* Real part of Z. */
__MATHDECL (_Mdouble_,creal, (_Mdouble_complex_ __z));
/* Now some optimized versions. GCC has handy notations for these
functions. Recent GCC handles these as builtin functions so does
not need inlines. */
#if defined __GNUC__ && !__GNUC_PREREQ (2, 97) && defined __OPTIMIZE__
/* Imaginary part of Z. */
extern __inline _Mdouble_
__MATH_PRECNAME(cimag) (_Mdouble_complex_ __z) __THROW
{
return __imag__ __z;
}
/* Real part of Z. */
extern __inline _Mdouble_
__MATH_PRECNAME(creal) (_Mdouble_complex_ __z) __THROW
{
return __real__ __z;
}
/* Complex conjugate of Z. */
extern __inline _Mdouble_complex_
__MATH_PRECNAME(conj) (_Mdouble_complex_ __z) __THROW
{
return __extension__ ~__z;
}
#endif

View File

@ -0,0 +1,107 @@
/* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
/*
* ISO C99: 7.3 Complex arithmetic <complex.h>
*/
#ifndef _COMPLEX_H
#define _COMPLEX_H 1
#include <features.h>
/* Get general and ISO C99 specific information. */
#include <bits/mathdef.h>
__BEGIN_DECLS
/* We might need to add support for more compilers here. But since ISO
C99 is out hopefully all maintained compilers will soon provide the data
types `float complex' and `double complex'. */
#if __GNUC_PREREQ (2, 7) && !__GNUC_PREREQ (2, 97)
# define _Complex __complex__
#endif
#define complex _Complex
/* Narrowest imaginary unit. This depends on the floating-point
evaluation method.
XXX This probably has to go into a gcc related file. */
#define _Complex_I (__extension__ 1.0iF)
/* Another more descriptive name is `I'.
XXX Once we have the imaginary support switch this to _Imaginary_I. */
#undef I
#define I _Complex_I
/* The file <bits/cmathcalls.h> contains the prototypes for all the
actual math functions. These macros are used for those prototypes,
so we can easily declare each function as both `name' and `__name',
and can declare the float versions `namef' and `__namef'. */
#define __MATHCALL(function, args) \
__MATHDECL (_Mdouble_complex_,function, args)
#define __MATHDECL(type, function, args) \
__MATHDECL_1(type, function, args); \
__MATHDECL_1(type, __CONCAT(__,function), args)
#define __MATHDECL_1(type, function, args) \
extern type __MATH_PRECNAME(function) args __THROW
#define _Mdouble_ double
#define __MATH_PRECNAME(name) name
#include <bits/cmathcalls.h>
#undef _Mdouble_
#undef __MATH_PRECNAME
/* Now the float versions. */
#ifndef _Mfloat_
# define _Mfloat_ float
#endif
#define _Mdouble_ _Mfloat_
#ifdef __STDC__
# define __MATH_PRECNAME(name) name##f
#else
# define __MATH_PRECNAME(name) name/**/f
#endif
#include <bits/cmathcalls.h>
#undef _Mdouble_
#undef __MATH_PRECNAME
/* And the long double versions. It is non-critical to define them
here unconditionally since `long double' is required in ISO C99. */
#if __STDC__ - 0 || __GNUC__ - 0 && !defined __NO_LONG_DOUBLE_MATH
# ifndef _Mlong_double_
# define _Mlong_double_ long double
# endif
# define _Mdouble_ _Mlong_double_
# ifdef __STDC__
# define __MATH_PRECNAME(name) name##l
# else
# define __MATH_PRECNAME(name) name/**/l
# endif
# include <bits/cmathcalls.h>
#endif
#undef _Mdouble_
#undef __MATH_PRECNAME
#undef __MATHDECL_1
#undef __MATHDECL
#undef __MATHCALL
__END_DECLS
#endif /* complex.h */