Build Fix -- compatibility issue with newer autoconf
[sxemacs] / src / ent / ent-float.h
1 /*
2   ent-float.h -- Fixed Precision Float Functions
3   Copyright (C) 2005, 2006 Sebastian Freundt
4
5   Author:  Sebastian Freundt
6
7 This file is part of SXEmacs
8
9 SXEmacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 SXEmacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
21
22
23 #ifndef INCLUDED_ent_float_h_
24 #define INCLUDED_ent_float_h_
25
26 #ifdef UNO
27 /* Uno complains about several inline functions that include conditions with
28    assignments and side effects if we don't do this */
29 #undef __GNUC__
30 #endif
31
32 /* debugging stuff */
33 #define ENT_DEBUG_FPFLOAT(args...)      ENT_DEBUG("[fpfloat]: " args)
34
35 #ifdef HAVE_MATHERR
36 /* Work around symbol conflict on Linux/glibc */
37 #ifndef DOMAIN
38 /* SysV matherr is not defined if _BSD_SOURCE is used, and on Linux X11 */
39 /* is compiled with _BSD_SOURCE which can also change the size of other */
40 /* types.  The configure test for matherr is broken. */
41 /* Bah.  Good riddance to bad rubbish. */
42 #undef HAVE_MATHERR
43 #endif
44 #endif
45
46 #ifdef NO_MATHERR
47 #undef HAVE_MATHERR
48 #endif
49
50 #ifdef HAVE_MATHERR
51 # ifdef FLOAT_CHECK_ERRNO
52 #  undef FLOAT_CHECK_ERRNO
53 # endif
54 # ifdef FLOAT_CHECK_DOMAIN
55 #  undef FLOAT_CHECK_DOMAIN
56 # endif
57 #endif
58
59 #ifndef NO_FLOAT_CHECK_ERRNO
60 #define FLOAT_CHECK_ERRNO
61 #endif
62
63 #if defined FLOAT_CHECK_ERRNO && defined HAVE_ERRNO_H
64 # include <errno.h>
65 #endif
66
67 #include <ent/ent-optable.h>
68 \f
69 extern Lisp_Object Qfloat;
70
71 extern void print_float(Lisp_Object, Lisp_Object, int);
72 extern void float_to_string(char*, fpfloat, int);
73
74 /* Note: the 'unused_next_' field exists only to ensure that the
75    `next' pointer fits within the structure, for the purposes of the
76    free list.  This makes a difference in the unlikely case of
77    sizeof(double) being smaller than sizeof(void *). */
78
79 typedef struct Lisp_Float Lisp_Float;
80 struct Lisp_Float {
81         struct lrecord_header lheader;
82         union {
83                 fpfloat fpf;
84                 struct Lisp_Float *unused_next_;
85         } data;
86 };
87
88 DECLARE_LRECORD(float, Lisp_Float);
89 #define XFLOAT(x)               XRECORD(x, float, Lisp_Float)
90 #define XSETFLOAT(x, p)         XSETRECORD(x, p, float)
91 #define FLOATP(x)               RECORDP(x, float)
92 #define CHECK_FLOAT(x)          CHECK_RECORD(x, float)
93 #define CONCHECK_FLOAT(x)       CONCHECK_RECORD(x, float)
94
95 #define float_data(f)           ((f)->data.fpf)
96 #define XFLOAT_DATA(x)          float_data(XFLOAT(x))
97 #define XFLOATINT(n)            extract_float(n)
98
99 extern Lisp_Object Vmost_positive_float;
100 extern Lisp_Object Vmost_negative_float;
101 extern Lisp_Object Vleast_positive_float;
102 extern Lisp_Object Vleast_negative_float;
103 extern Lisp_Object Vleast_positive_normalised_float;
104 extern Lisp_Object Vleast_negative_normalised_float;
105 extern Lisp_Object Vfloat_epsilon;
106 extern Fixnum max_float_print_size;
107
108 extern void init_optables_FLOAT_T(void);
109 extern void init_ent_float(void);
110 extern void syms_of_ent_float(void);
111 extern void vars_of_ent_float(void);
112 extern Lisp_Object make_float(fpfloat);
113
114 #include "ent-inf.h"
115 #include "ent-strflt.h"
116 #include "ent-lift.h"
117
118 #if fpfloat_long_double_p && defined(HAVE_MATHS_LDBL_MAX)
119 # define FPFLOAT_MAX    LDBL_MAX
120 #elif fpfloat_double_p && defined(HAVE_MATHS_DBL_MAX)
121 # define FPFLOAT_MAX    DBL_MAX
122 #elif fpfloat_double_p && defined(HAVE_MATHS_MAXDOUBLE)
123 # define FPFLOAT_MAX    MAXDOUBLE
124 #endif
125 #if fpfloat_long_double_p && defined(HAVE_MATHS_LDBL_MIN)
126 # define FPFLOAT_MIN    LDBL_MIN
127 #elif fpfloat_double_p && defined(HAVE_MATHS_DBL_MIN)
128 # define FPFLOAT_MIN    DBL_MIN
129 #elif fpfloat_double_p && defined(HAVE_MATHS_MINDOUBLE)
130 # define FPFLOAT_MAX    MINDOUBLE
131 #endif
132
133 \f
134 extern Lisp_Object Qrange_error;
135 EXFUN(Fsignal, 2);
136
137 extern_inline fpfloat ent_float(Lisp_Object);
138 #define extract_float   ent_float
139
140 extern_inline fpfloat
141 ent_float(Lisp_Object num)
142 {
143         num = ent_lift(num, FLOAT_T, NULL);
144         if (FLOATP(num))
145                 return XFLOAT_DATA(num);
146         else
147                 Fsignal(Qrange_error, num);
148         return 0.0f;
149 }
150
151 #endif /* INCLUDED_ent_float_h_ */