Skip to content

Commit da782e7

Browse files
committed
Add various complex math routines from OpenBSD.
1 parent f876e59 commit da782e7

37 files changed

Lines changed: 3005 additions & 0 deletions

src/s_cabs.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* $OpenBSD: s_cabs.c,v 1.6 2013/07/03 04:46:36 espie Exp $ */
2+
/*
3+
* Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org>
4+
*
5+
* Permission to use, copy, modify, and distribute this software for any
6+
* purpose with or without fee is hereby granted, provided that the above
7+
* copyright notice and this permission notice appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
*/
17+
18+
#include <complex.h>
19+
#include <float.h>
20+
#include <math.h>
21+
22+
double
23+
cabs(double complex z)
24+
{
25+
return hypot(__real__ z, __imag__ z);
26+
}
27+
28+
#if LDBL_MANT_DIG == DBL_MANT_DIG
29+
__strong_alias(cabsl, cabs);
30+
#endif /* LDBL_MANT_DIG == DBL_MANT_DIG */

src/s_cabsf.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* $OpenBSD: s_cabsf.c,v 1.1 2008/09/07 20:36:09 martynas Exp $ */
2+
/*
3+
* Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org>
4+
*
5+
* Permission to use, copy, modify, and distribute this software for any
6+
* purpose with or without fee is hereby granted, provided that the above
7+
* copyright notice and this permission notice appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
*/
17+
18+
#include <complex.h>
19+
#include <math.h>
20+
21+
float
22+
cabsf(float complex z)
23+
{
24+
return hypotf(__real__ z, __imag__ z);
25+
}

src/s_cabsl.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* $OpenBSD: s_cabsl.c,v 1.1 2011/07/08 19:25:31 martynas Exp $ */
2+
3+
/*
4+
* Copyright (c) 2011 Martynas Venckus <martynas@openbsd.org>
5+
*
6+
* Permission to use, copy, modify, and distribute this software for any
7+
* purpose with or without fee is hereby granted, provided that the above
8+
* copyright notice and this permission notice appear in all copies.
9+
*
10+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
19+
#include <complex.h>
20+
#include <math.h>
21+
22+
long double
23+
cabsl(long double complex z)
24+
{
25+
return hypotl(__real__ z, __imag__ z);
26+
}

src/s_cacos.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* $OpenBSD: s_cacos.c,v 1.6 2013/07/03 04:46:36 espie Exp $ */
2+
/*
3+
* Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
4+
*
5+
* Permission to use, copy, modify, and distribute this software for any
6+
* purpose with or without fee is hereby granted, provided that the above
7+
* copyright notice and this permission notice appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
*/
17+
18+
/* cacos()
19+
*
20+
* Complex circular arc cosine
21+
*
22+
*
23+
*
24+
* SYNOPSIS:
25+
*
26+
* double complex cacos();
27+
* double complex z, w;
28+
*
29+
* w = cacos (z);
30+
*
31+
*
32+
*
33+
* DESCRIPTION:
34+
*
35+
*
36+
* w = arccos z = PI/2 - arcsin z.
37+
*
38+
*
39+
*
40+
*
41+
* ACCURACY:
42+
*
43+
* Relative error:
44+
* arithmetic domain # trials peak rms
45+
* DEC -10,+10 5200 1.6e-15 2.8e-16
46+
* IEEE -10,+10 30000 1.8e-14 2.2e-15
47+
*/
48+
49+
#include <complex.h>
50+
#include <float.h>
51+
#include <math.h>
52+
53+
double complex
54+
cacos(double complex z)
55+
{
56+
double complex w;
57+
58+
w = casin (z);
59+
w = (M_PI_2 - creal (w)) - cimag (w) * I;
60+
return (w);
61+
}
62+
63+
#if LDBL_MANT_DIG == DBL_MANT_DIG
64+
__strong_alias(cacosl, cacos);
65+
#endif /* LDBL_MANT_DIG == DBL_MANT_DIG */

src/s_cacosf.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* $OpenBSD: s_cacosf.c,v 1.2 2011/07/20 19:28:33 martynas Exp $ */
2+
/*
3+
* Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
4+
*
5+
* Permission to use, copy, modify, and distribute this software for any
6+
* purpose with or without fee is hereby granted, provided that the above
7+
* copyright notice and this permission notice appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
*/
17+
18+
/* cacosf()
19+
*
20+
* Complex circular arc cosine
21+
*
22+
*
23+
*
24+
* SYNOPSIS:
25+
*
26+
* void cacosf();
27+
* cmplxf z, w;
28+
*
29+
* cacosf( &z, &w );
30+
*
31+
*
32+
*
33+
* DESCRIPTION:
34+
*
35+
*
36+
* w = arccos z = PI/2 - arcsin z.
37+
*
38+
*
39+
*
40+
*
41+
* ACCURACY:
42+
*
43+
* Relative error:
44+
* arithmetic domain # trials peak rms
45+
* IEEE -10,+10 30000 9.2e-6 1.2e-6
46+
*
47+
*/
48+
49+
#include <complex.h>
50+
#include <math.h>
51+
52+
float complex
53+
cacosf(float complex z)
54+
{
55+
float complex w;
56+
57+
w = casinf( z );
58+
w = ((float)M_PI_2 - crealf (w)) - cimagf (w) * I;
59+
return (w);
60+
}

src/s_cacosh.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* $OpenBSD: s_cacosh.c,v 1.6 2013/07/03 04:46:36 espie Exp $ */
2+
/*
3+
* Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
4+
*
5+
* Permission to use, copy, modify, and distribute this software for any
6+
* purpose with or without fee is hereby granted, provided that the above
7+
* copyright notice and this permission notice appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
*/
17+
18+
/* cacosh
19+
*
20+
* Complex inverse hyperbolic cosine
21+
*
22+
*
23+
*
24+
* SYNOPSIS:
25+
*
26+
* double complex cacosh();
27+
* double complex z, w;
28+
*
29+
* w = cacosh (z);
30+
*
31+
*
32+
*
33+
* DESCRIPTION:
34+
*
35+
* acosh z = i acos z .
36+
*
37+
* ACCURACY:
38+
*
39+
* Relative error:
40+
* arithmetic domain # trials peak rms
41+
* IEEE -10,+10 30000 1.6e-14 2.1e-15
42+
*
43+
*/
44+
45+
#include <complex.h>
46+
#include <float.h>
47+
#include <math.h>
48+
49+
double complex
50+
cacosh(double complex z)
51+
{
52+
double complex w;
53+
54+
w = I * cacos (z);
55+
return (w);
56+
}
57+
58+
#if LDBL_MANT_DIG == DBL_MANT_DIG
59+
__strong_alias(cacoshl, cacosh);
60+
#endif /* LDBL_MANT_DIG == DBL_MANT_DIG */

src/s_cacoshf.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* $OpenBSD: s_cacoshf.c,v 1.1 2008/09/07 20:36:09 martynas Exp $ */
2+
/*
3+
* Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
4+
*
5+
* Permission to use, copy, modify, and distribute this software for any
6+
* purpose with or without fee is hereby granted, provided that the above
7+
* copyright notice and this permission notice appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
*/
17+
18+
/* cacoshf
19+
*
20+
* Complex inverse hyperbolic cosine
21+
*
22+
*
23+
*
24+
* SYNOPSIS:
25+
*
26+
* float complex cacoshf();
27+
* float complex z, w;
28+
*
29+
* w = cacoshf (z);
30+
*
31+
*
32+
*
33+
* DESCRIPTION:
34+
*
35+
* acosh z = i acos z .
36+
*
37+
* ACCURACY:
38+
*
39+
* Relative error:
40+
* arithmetic domain # trials peak rms
41+
* IEEE -10,+10 30000 1.6e-14 2.1e-15
42+
*
43+
*/
44+
45+
#include <complex.h>
46+
#include <math.h>
47+
48+
float complex
49+
cacoshf(float complex z)
50+
{
51+
float complex w;
52+
53+
w = I * cacosf (z);
54+
return (w);
55+
}

src/s_cacoshl.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* $OpenBSD: s_cacoshl.c,v 1.1 2011/07/08 19:25:31 martynas Exp $ */
2+
3+
/*
4+
* Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
5+
*
6+
* Permission to use, copy, modify, and distribute this software for any
7+
* purpose with or without fee is hereby granted, provided that the above
8+
* copyright notice and this permission notice appear in all copies.
9+
*
10+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
19+
/* cacoshl
20+
*
21+
* Complex inverse hyperbolic cosine
22+
*
23+
*
24+
*
25+
* SYNOPSIS:
26+
*
27+
* long double complex cacoshl();
28+
* long double complex z, w;
29+
*
30+
* w = cacoshl (z);
31+
*
32+
*
33+
*
34+
* DESCRIPTION:
35+
*
36+
* acosh z = i acos z .
37+
*
38+
* ACCURACY:
39+
*
40+
* Relative error:
41+
* arithmetic domain # trials peak rms
42+
* IEEE -10,+10 30000 1.6e-14 2.1e-15
43+
*
44+
*/
45+
46+
#include <complex.h>
47+
#include <math.h>
48+
49+
long double complex
50+
cacoshl(long double complex z)
51+
{
52+
long double complex w;
53+
54+
w = I * cacosl(z);
55+
return (w);
56+
}

0 commit comments

Comments
 (0)