OSDN Git Service

4ceb7bf9aeba3c0028844fc57fa301fe6982c2d7
[mingw/mingw-org-wsl.git] / src / libcrt / math / lround_generic.c
1 /**
2  * @file lround_generic.c
3  * @copy 2012 MinGW.org project
4  *
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:
11  * 
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
14  * Software.
15  * 
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.
23  */
24
25 /*
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
30  * functions.
31  */
32 #ifndef FUNCTION
33 /*
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'.
39  */
40 #define FUNCTION lround
41 #endif
42
43 #include "round_internal.h"
44
45 #include <limits.h>
46 #include <errno.h>
47
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.
55  */
56 RETURN_TYPE FUNCTION( INPUT_TYPE x )
57 {
58   if( !isfinite( x ) || !isfinite( x = round_internal( x ) )
59   ||  (x > MAX_RETURN_VALUE) || (x < MIN_RETURN_VALUE)        )
60     /*
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.
66      */
67     errno = EDOM;
68
69   return (RETURN_TYPE)(x);
70 }
71
72 /* $RCSfile: lround_generic.c,v $$Revision: 1.1 $: end of file */