2 ent-float.h -- Fixed Precision Float Functions
3 Copyright (C) 2005, 2006 Sebastian Freundt
5 Author: Sebastian Freundt
7 This file is part of SXEmacs
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.
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.
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/>. */
23 #ifndef INCLUDED_ent_float_h_
24 #define INCLUDED_ent_float_h_
27 /* Uno complains about several inline functions that include conditions with
28 assignments and side effects if we don't do this */
33 #define ENT_DEBUG_FPFLOAT(args...) ENT_DEBUG("[fpfloat]: " args)
36 /* Work around symbol conflict on Linux/glibc */
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. */
51 # ifdef FLOAT_CHECK_ERRNO
52 # undef FLOAT_CHECK_ERRNO
54 # ifdef FLOAT_CHECK_DOMAIN
55 # undef FLOAT_CHECK_DOMAIN
59 #ifndef NO_FLOAT_CHECK_ERRNO
60 #define FLOAT_CHECK_ERRNO
63 #if defined FLOAT_CHECK_ERRNO && defined HAVE_ERRNO_H
68 extern Lisp_Object Qfloat;
70 extern void print_float(Lisp_Object, Lisp_Object, int);
71 extern void float_to_string(char*, fpfloat);
73 /* Note: the 'unused_next_' field exists only to ensure that the
74 `next' pointer fits within the structure, for the purposes of the
75 free list. This makes a difference in the unlikely case of
76 sizeof(double) being smaller than sizeof(void *). */
78 typedef struct Lisp_Float Lisp_Float;
80 struct lrecord_header lheader;
83 struct Lisp_Float *unused_next_;
87 DECLARE_LRECORD(float, Lisp_Float);
88 #define XFLOAT(x) XRECORD(x, float, Lisp_Float)
89 #define XSETFLOAT(x, p) XSETRECORD(x, p, float)
90 #define FLOATP(x) RECORDP(x, float)
91 #define CHECK_FLOAT(x) CHECK_RECORD(x, float)
92 #define CONCHECK_FLOAT(x) CONCHECK_RECORD(x, float)
94 #define float_data(f) ((f)->data.fpf)
95 #define XFLOAT_DATA(x) float_data(XFLOAT(x))
96 #define XFLOATINT(n) extract_float(n)
98 extern Lisp_Object Vmost_positive_float;
99 extern Lisp_Object Vmost_negative_float;
100 extern Lisp_Object Vleast_positive_float;
101 extern Lisp_Object Vleast_negative_float;
102 extern Lisp_Object Vleast_positive_normalised_float;
103 extern Lisp_Object Vleast_negative_normalised_float;
104 extern Lisp_Object Vfloat_epsilon;
105 extern Fixnum max_float_print_size;
107 extern void init_optables_FLOAT_T(void);
108 extern void init_ent_float(void);
109 extern void syms_of_ent_float(void);
110 extern void vars_of_ent_float(void);
111 extern Lisp_Object make_float(fpfloat);
114 #include "ent-strflt.h"
116 #if fpfloat_long_double_p && defined(HAVE_MATHS_LDBL_MAX)
117 # define FPFLOAT_MAX LDBL_MAX
118 #elif fpfloat_double_p && defined(HAVE_MATHS_DBL_MAX)
119 # define FPFLOAT_MAX DBL_MAX
120 #elif fpfloat_double_p && defined(HAVE_MATHS_MAXDOUBLE)
121 # define FPFLOAT_MAX MAXDOUBLE
123 #if fpfloat_long_double_p && defined(HAVE_MATHS_LDBL_MIN)
124 # define FPFLOAT_MIN LDBL_MIN
125 #elif fpfloat_double_p && defined(HAVE_MATHS_DBL_MIN)
126 # define FPFLOAT_MIN DBL_MIN
127 #elif fpfloat_double_p && defined(HAVE_MATHS_MINDOUBLE)
128 # define FPFLOAT_MAX MINDOUBLE
132 extern Lisp_Object Qrange_error;
135 extern_inline fpfloat ent_float(Lisp_Object);
136 #define extract_float ent_float
138 extern_inline fpfloat
139 ent_float(Lisp_Object num)
141 num = ent_lift(num, FLOAT_T, NULL);
143 return XFLOAT_DATA(num);
145 Fsignal(Qrange_error, num);
149 #endif /* INCLUDED_ent_float_h_ */