Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1906 | serge | 1 | /* |
2 | * lround_generic.c |
||
3 | * |
||
4 | * $Id: lround_generic.c,v 1.1 2008/06/03 18:42:21 keithmarshall Exp $ |
||
5 | * |
||
6 | * Provides a generic implementation for the `lround()', `lroundf()', |
||
7 | * `lroundl()', `llround()', `llroundf()' and `llroundl()' functions; |
||
8 | * compile with `-D FUNCTION=name', with `name' set to each of these |
||
9 | * six in turn, to create separate object files for each of the six |
||
10 | * functions. |
||
11 | * |
||
12 | * Written by Keith Marshall |
||
13 | * |
||
14 | * This is free software. You may redistribute and/or modify it as you |
||
15 | * see fit, without restriction of copyright. |
||
16 | * |
||
17 | * This software is provided "as is", in the hope that it may be useful, |
||
18 | * but WITHOUT WARRANTY OF ANY KIND, not even any implied warranty of |
||
19 | * MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE. At no |
||
20 | * time will the author accept any form of liability for any damages, |
||
21 | * however caused, resulting from the use of this software. |
||
22 | * |
||
23 | */ |
||
24 | #ifndef FUNCTION |
||
25 | /* |
||
26 | * Normally specified with `-D FUNCTION=name', on the command line. |
||
27 | * Valid FUNCTION names are `lround', `lroundf', `lroundl', `llround' |
||
28 | * `llroundf' and `llroundl'; specifying anything else will most likely |
||
29 | * cause a compilation error. If user did not specify an appropriate |
||
30 | * FUNCTION name, default to `lround'. |
||
31 | */ |
||
32 | #define FUNCTION lround |
||
33 | #endif |
||
34 | |||
35 | #include "round_internal.h" |
||
36 | |||
37 | #include |
||
38 | #include |
||
39 | |||
40 | /* Generic implementation. |
||
41 | * The user is required to specify the FUNCTION name; |
||
42 | * the RETURN_TYPE and INPUT_TYPE macros resolve to appropriate |
||
43 | * type declarations, to match the selected FUNCTION prototype, |
||
44 | * while RETURN_MAX and RETURN_MIN map to the correspondingly |
||
45 | * appropriate limits.h manifest values, to establish the |
||
46 | * valid range for the RETURN_TYPE. |
||
47 | */ |
||
48 | RETURN_TYPE FUNCTION( INPUT_TYPE x ) |
||
49 | { |
||
50 | if( !isfinite( x ) || !isfinite( x = round_internal( x ) ) |
||
51 | || (x > MAX_RETURN_VALUE) || (x < MIN_RETURN_VALUE) ) |
||
52 | /* |
||
53 | * Undefined behaviour... |
||
54 | * POSIX requires us to report a domain error; ANSI C99 says we |
||
55 | * _may_ report a range error, and previous MinGW implementation |
||
56 | * set `errno = ERANGE' here; we change that, conforming to the |
||
57 | * stricter requiremment of the POSIX standard. |
||
58 | */ |
||
59 | errno = EDOM; |
||
60 | |||
61 | return (RETURN_TYPE)(x); |
||
62 | } |
||
63 | |||
64 | /* $RCSfile: lround_generic.c,v $$Revision: 1.1 $: end of file */> |