OSDN Git Service

fd000279ba60b1a32d88a91e41fc4b7437fca557
[mingw/mingw-org-wsl.git] / mingwrt / mingwex / complex / cabs_generic.c
1 /*
2  * cabs_generic.c
3  *
4  * $Id$
5  *
6  * Compute the modulus of a complex number; this provides a generic
7  * implementation for the cabs(), cabsf(), and cabsl() functions.
8  *
9  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
10  * This is an adaptation of original contributions by Danny Smith
11  * Copyright (C) 2003, 2015, MinGW.org Project
12  *
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a
15  * copy of this software and associated documentation files (the "Software"),
16  * to deal in the Software without restriction, including without limitation
17  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18  * and/or sell copies of the Software, and to permit persons to whom the
19  * Software is furnished to do so, subject to the following conditions:
20  *
21  * The above copyright notice, this permission notice, and the following
22  * disclaimer shall be included in all copies or substantial portions of
23  * the Software.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
28  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
31  * DEALINGS IN THE SOFTWARE.
32  *
33  *
34  * This is a generic implementation for all of the csqrt(), csqrtl(),
35  * and csqrth() functions; each is to be compiled separately, i.e.
36  *
37  *   gcc -D FUNCTION=cabs  -o cabs.o  cabs_generic.c
38  *   gcc -D FUNCTION=cabsl -o cabsl.o cabs_generic.c
39  *   gcc -D FUNCTION=cabsf -o cabsf.o cabs_generic.c
40  *
41  */
42 #include <math.h>
43 #include <complex.h>
44
45 #ifndef FUNCTION
46 /* If user neglected to specify it, the default compilation is for
47  * the cabs() function.
48  */
49 # define FUNCTION cabs
50 #endif
51
52 #define argtype_cabs  double
53 #define argtype_cabsl long double
54 #define argtype_cabsf float
55
56 #define PASTE(PREFIX,SUFFIX) PREFIX##SUFFIX
57 #define mapfunc(NAME) mapname(mapfunc_,FUNCTION)(NAME)
58 #define mapname(PREFIX,SUFFIX) PASTE(PREFIX,SUFFIX)
59
60 #define ARGTYPE(FUNCTION) PASTE(argtype_,FUNCTION)
61
62 #define mapfunc_cabs(NAME)  NAME
63 #define mapfunc_cabsl(NAME) PASTE(NAME,l)
64 #define mapfunc_cabsf(NAME) PASTE(NAME,f)
65
66 /* Define the generic function implementation.
67  */
68 ARGTYPE(FUNCTION) FUNCTION( ARGTYPE(FUNCTION) complex Z )
69 {
70   return mapfunc(hypot)( __real__ Z, __imag__ Z );
71 }
72
73 /* $RCSfile$: end of file */