2 * @file lround_generic.c
3 * @copy 2012 MinGW.org project
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
26 * Provides a generic implementation for the `lround()', `lroundf()',
27 * `lroundl()', `llround()', `llroundf()' and `llroundl()' functions;
28 * compile with `-D FUNCTION=name', with `name' set to each of these
29 * six in turn, to create separate object files for each of the six
34 * Normally specified with `-D FUNCTION=name', on the command line.
35 * Valid FUNCTION names are `lround', `lroundf', `lroundl', `llround'
36 * `llroundf' and `llroundl'; specifying anything else will most likely
37 * cause a compilation error. If user did not specify an appropriate
38 * FUNCTION name, default to `lround'.
40 #define FUNCTION lround
43 #include "round_internal.h"
48 /* Generic implementation.
49 * The user is required to specify the FUNCTION name;
50 * the RETURN_TYPE and INPUT_TYPE macros resolve to appropriate
51 * type declarations, to match the selected FUNCTION prototype,
52 * while RETURN_MAX and RETURN_MIN map to the correspondingly
53 * appropriate limits.h manifest values, to establish the
54 * valid range for the RETURN_TYPE.
56 RETURN_TYPE FUNCTION( INPUT_TYPE x )
58 if( !isfinite( x ) || !isfinite( x = round_internal( x ) )
59 || (x > MAX_RETURN_VALUE) || (x < MIN_RETURN_VALUE) )
61 * Undefined behaviour...
62 * POSIX requires us to report a domain error; ANSI C99 says we
63 * _may_ report a range error, and previous MinGW implementation
64 * set `errno = ERANGE' here; we change that, conforming to the
65 * stricter requiremment of the POSIX standard.
69 return (RETURN_TYPE)(x);
72 /* $RCSfile: lround_generic.c,v $$Revision: 1.1 $: end of file */