6 * Compute the modulus of a complex number; this provides a generic
7 * implementation for the cabs(), cabsf(), and cabsl() functions.
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
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:
21 * The above copyright notice, this permission notice, and the following
22 * disclaimer shall be included in all copies or substantial portions of
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.
34 * This is a generic implementation for all of the csqrt(), csqrtl(),
35 * and csqrth() functions; each is to be compiled separately, i.e.
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
46 /* If user neglected to specify it, the default compilation is for
47 * the cabs() function.
49 # define FUNCTION cabs
52 #define argtype_cabs double
53 #define argtype_cabsl long double
54 #define argtype_cabsf float
56 #define PASTE(PREFIX,SUFFIX) PREFIX##SUFFIX
57 #define mapfunc(NAME) mapname(mapfunc_,FUNCTION)(NAME)
58 #define mapname(PREFIX,SUFFIX) PASTE(PREFIX,SUFFIX)
60 #define ARGTYPE(FUNCTION) PASTE(argtype_,FUNCTION)
62 #define mapfunc_cabs(NAME) NAME
63 #define mapfunc_cabsl(NAME) PASTE(NAME,l)
64 #define mapfunc_cabsf(NAME) PASTE(NAME,f)
66 /* Define the generic function implementation.
68 ARGTYPE(FUNCTION) FUNCTION( ARGTYPE(FUNCTION) complex Z )
70 return mapfunc(hypot)( __real__ Z, __imag__ Z );
73 /* $RCSfile$: end of file */