OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / user / a60 / conv.h
1 /*
2  * Copyright (C) 1991,1992 Erik Schoenfelder (schoenfr@ibr.cs.tu-bs.de)
3  *
4  * This file is part of NASE A60.
5  * 
6  * NASE A60 is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * NASE A60 is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with NASE A60; see the file COPYING.  If not, write to the Free
18  * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  * conv.h:                                      oct '90
21  *
22  * Erik Schoenfelder (schoenfr@ibr.cs.tu-bs.de)
23  *
24  * conversion of numerical values.
25  * 'real' to 'integer'  and  'integer' to 'real'.
26  */
27
28 #ifndef CONV_H_HOOK
29 #define CONV_H_HOOK
30
31
32 #ifdef __GNUC__
33 # include <limits.h>
34 #else /* ! __GNUC__ */
35 # ifndef NO_LIMITS_H
36 #  include <limits.h>
37 # endif /* NO_LIMITS_H */
38 #endif /* ! __GNUC__ */
39
40
41 /*
42  * use these values, if not avail ...
43  */
44
45 #ifndef LONG_MAX
46 #define LONG_MAX         2147483647L
47 #endif
48 #ifndef LONG_MIN
49 /*
50  * problem using -2147483648: if '-' is scanned as unary minus, the
51  * positive number is greater than LONG_MAX ... 
52  */
53 #define LONG_MIN        (-LONG_MAX-1)
54 #endif
55
56
57
58 /*
59  * conversion of integer value to real value (and vice versa).
60  */
61
62 #define IVAL2RVAL(l)    ((double) (l))
63
64 #define RVAL2IVAL(x)    (((x) + 0.5 >= (double) LONG_MAX) \
65                          ? LONG_MAX \
66                          : ((x) - 0.5 <= (double) LONG_MIN) \
67                          ? LONG_MIN \
68                          : ((x) > 0) ? (long) ((x) + 0.5) \
69                                      : (long) ((x) - 0.5))
70
71 #define RVALTRUNC(x)    (((x) > (double) LONG_MAX) \
72                          ? LONG_MAX \
73                          : ((x) < (double) LONG_MIN) \
74                          ? LONG_MIN \
75                          : (long) (x))
76
77 #undef P
78
79 #endif /* CONV_H_HOOK */