Skip to content

Commit

Permalink
libroot: added a complex.h header based on ...
Browse files Browse the repository at this point in the history
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/complex.h.html
* added missing parts from glibc.
* x86_64 was already complete, x86 was missing a few functions.
* should help with #12202, provided that the gcc4 buildtools are rebuilt.
  • Loading branch information
korli committed Jul 10, 2015
1 parent b6f0f88 commit a834469
Show file tree
Hide file tree
Showing 23 changed files with 1,218 additions and 17 deletions.
85 changes: 85 additions & 0 deletions headers/posix/complex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright 2015 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _COMPLEX_H_
#define _COMPLEX_H_

#ifdef __GNUC__
# if __STDC_VERSION__ < 199901L
# define _Complex __complex__
#endif
#define _Complex_I ((float _Complex)1.0i)
#endif

#define complex _Complex
#define I _Complex_I

extern double cabs(double complex);
extern float cabsf(float complex);
extern long double cabsl(long double complex);
extern double complex cacos(double complex);
extern float complex cacosf(float complex);
extern double complex cacosh(double complex);
extern float complex cacoshf(float complex);
extern long double complex cacoshl(long double complex);
extern long double complex cacosl(long double complex);
extern double carg(double complex);
extern float cargf(float complex);
extern long double cargl(long double complex);
extern double complex casin(double complex);
extern float complex casinf(float complex);
extern double complex casinh(double complex);
extern float complex casinhf(float complex);
extern long double complex casinhl(long double complex);
extern long double complex casinl(long double complex);
extern double complex catan(double complex);
extern float complex catanf(float complex);
extern double complex catanh(double complex);
extern float complex catanhf(float complex);
extern long double complex catanhl(long double complex);
extern long double complex catanl(long double complex);
extern double complex ccos(double complex);
extern float complex ccosf(float complex);
extern double complex ccosh(double complex);
extern float complex ccoshf(float complex);
extern long double complex ccoshl(long double complex);
extern long double complex ccosl(long double complex);
extern double complex cexp(double complex);
extern float complex cexpf(float complex);
extern long double complex cexpl(long double complex);
extern double cimag(double complex);
extern float cimagf(float complex);
extern long double cimagl(long double complex);
extern double complex clog(double complex);
extern float complex clogf(float complex);
extern long double complex clogl(long double complex);
extern double complex conj(double complex);
extern float complex conjf(float complex);
extern long double complex conjl(long double complex);
extern double complex cpow(double complex, double complex);
extern float complex cpowf(float complex, float complex);
extern long double complex cpowl(long double complex, long double complex);
extern double complex cproj(double complex);
extern float complex cprojf(float complex);
extern long double complex cprojl(long double complex);
extern double creal(double complex);
extern float crealf(float complex);
extern long double creall(long double complex);
extern double complex csin(double complex);
extern float complex csinf(float complex);
extern double complex csinh(double complex);
extern float complex csinhf(float complex);
extern long double complex csinhl(long double complex);
extern long double complex csinl(long double complex);
extern double complex csqrt(double complex);
extern float complex csqrtf(float complex);
extern long double complex csqrtl(long double complex);
extern double complex ctan(double complex);
extern float complex ctanf(float complex);
extern double complex ctanh(double complex);
extern float complex ctanhf(float complex);
extern long double complex ctanhl(long double complex);
extern long double complex ctanl(long double complex);

#endif /* _COMPLEX_H_ */
1 change: 1 addition & 0 deletions src/system/libroot/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
posix_gnu_iconv.o
posix_gnu_libio.o
posix_gnu_locale.o
posix_gnu_math.o
posix_gnu_misc.o
posix_gnu_regex.o
posix_gnu_stdio.o
Expand Down
1 change: 1 addition & 0 deletions src/system/libroot/posix/glibc/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SubInclude HAIKU_TOP src system libroot posix glibc extensions ;
SubInclude HAIKU_TOP src system libroot posix glibc iconv ;
SubInclude HAIKU_TOP src system libroot posix glibc libio ;
SubInclude HAIKU_TOP src system libroot posix glibc locale ;
SubInclude HAIKU_TOP src system libroot posix glibc math ;
SubInclude HAIKU_TOP src system libroot posix glibc misc ;
SubInclude HAIKU_TOP src system libroot posix glibc regex ;
SubInclude HAIKU_TOP src system libroot posix glibc stdio-common ;
Expand Down
34 changes: 17 additions & 17 deletions src/system/libroot/posix/glibc/arch/x86/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ 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_ccos.c s_ccosf.c #s_ccosl.c
s_ccosh.c s_ccoshf.c #s_ccoshl.c
s_clog.c s_clogf.c #s_clogl.c
s_clog10.c s_clog10f.c #s_clog10l.c
s_cpow.c s_cpowf.c #s_cpowl.c
s_cproj.c s_cprojf.c #s_cprojl.c
s_csin.c s_csinf.c #s_csinl.c
s_csinh.c s_csinhf.c #s_csinhl.c
s_csqrt.c s_csqrtf.c #s_csqrtl.c
s_ctan.c s_ctanf.c #s_ctanl.c
s_ctanh.c s_ctanhf.c #s_ctanhl.c
s_cacos.c s_cacosf.c s_cacosl.c
s_cacosh.c s_cacoshf.c s_cacoshl.c
s_casin.c s_casinf.c s_casinl.c
s_casinh.c s_casinhf.c s_casinhl.c
s_catan.c s_catanf.c s_catanl.c
s_catanh.c s_catanhf.c s_catanhl.c
s_ccos.c s_ccosf.c s_ccosl.c
s_ccosh.c s_ccoshf.c s_ccoshl.c
s_clog.c s_clogf.c s_clogl.c
s_clog10.c s_clog10f.c s_clog10l.c
s_cpow.c s_cpowf.c s_cpowl.c
s_cproj.c s_cprojf.c s_cprojl.c
s_csin.c s_csinf.c s_csinl.c
s_csinh.c s_csinhf.c s_csinhl.c
s_csqrt.c s_csqrtf.c s_csqrtl.c
s_ctan.c s_ctanf.c s_ctanl.c
s_ctanh.c s_ctanhf.c s_ctanhl.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
Expand Down
30 changes: 30 additions & 0 deletions src/system/libroot/posix/glibc/math/Jamfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
SubDir HAIKU_TOP src system libroot posix glibc math ;

SubDirCcFlags -D_GNU_SOURCE -DUSE_IN_LIBIO ;

local architectureObject ;
for architectureObject in [ MultiArchSubDirSetup ] {
on $(architectureObject) {
local architecture = $(TARGET_PACKAGING_ARCH) ;

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 math ;
SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ;

UsePrivateHeaders libroot ;

MergeObject <$(architecture)>posix_gnu_math.o :
cabs.c cabsf.c cabsl.c
carg.c cargf.c cargl.c
cimag.c cimagf.c cimagl.c
conj.c conjf.c conjl.c
creal.c crealf.c creall.c

k_casinh.c k_casinhf.c k_casinhl.c
;
}
}
32 changes: 32 additions & 0 deletions src/system/libroot/posix/glibc/math/cabs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Return the complex absolute value of double complex value.
Copyright (C) 1997-2015 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, see
<http://www.gnu.org/licenses/>. */

#include <complex.h>
#include <math.h>

double
__cabs (double _Complex z)
{
return __hypot (__real__ z, __imag__ z);
}
weak_alias (__cabs, cabs)
#ifdef NO_LONG_DOUBLE
strong_alias (__cabs, __cabsl)
weak_alias (__cabs, cabsl)
#endif
28 changes: 28 additions & 0 deletions src/system/libroot/posix/glibc/math/cabsf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Return the complex absolute value of float complex value.
Copyright (C) 1997-2015 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, see
<http://www.gnu.org/licenses/>. */

#include <complex.h>
#include <math.h>

float
__cabsf (float _Complex z)
{
return __hypotf (__real__ z, __imag__ z);
}
weak_alias (__cabsf, cabsf)
28 changes: 28 additions & 0 deletions src/system/libroot/posix/glibc/math/cabsl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Return the complex absolute value of long double complex value.
Copyright (C) 1997-2015 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, see
<http://www.gnu.org/licenses/>. */

#include <complex.h>
#include <math.h>

long double
__cabsl (long double _Complex z)
{
return __hypotl (__real__ z, __imag__ z);
}
weak_alias (__cabsl, cabsl)
32 changes: 32 additions & 0 deletions src/system/libroot/posix/glibc/math/carg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Compute argument of complex double value.
Copyright (C) 1997-2015 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, see
<http://www.gnu.org/licenses/>. */

#include <complex.h>
#include <math.h>

double
__carg (__complex__ double x)
{
return __atan2 (__imag__ x, __real__ x);
}
weak_alias (__carg, carg)
#ifdef NO_LONG_DOUBLE
strong_alias (__carg, __cargl)
weak_alias (__carg, cargl)
#endif
28 changes: 28 additions & 0 deletions src/system/libroot/posix/glibc/math/cargf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Compute argument of complex float value.
Copyright (C) 1997-2015 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, see
<http://www.gnu.org/licenses/>. */

#include <complex.h>
#include <math.h>

float
__cargf (__complex__ float x)
{
return __atan2f (__imag__ x, __real__ x);
}
weak_alias (__cargf, cargf)
28 changes: 28 additions & 0 deletions src/system/libroot/posix/glibc/math/cargl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Compute argument of complex long double value.
Copyright (C) 1997-2015 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, see
<http://www.gnu.org/licenses/>. */

#include <complex.h>
#include <math.h>

long double
__cargl (__complex__ long double x)
{
return __atan2l (__imag__ x, __real__ x);
}
weak_alias (__cargl, cargl)
31 changes: 31 additions & 0 deletions src/system/libroot/posix/glibc/math/cimag.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Return imaginary part of complex double value.
Copyright (C) 1997-2015 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, see
<http://www.gnu.org/licenses/>. */

#include <complex.h>

double
__cimag (double _Complex z)
{
return __imag__ z;
}
weak_alias (__cimag, cimag)
#ifdef NO_LONG_DOUBLE
strong_alias (__cimag, __cimagl)
weak_alias (__cimag, cimagl)
#endif

0 comments on commit a834469

Please sign in to comment.