Wand updates from Evgeny
[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 \f
68 extern Lisp_Object Qfloat;
69
70 extern void print_float(Lisp_Object, Lisp_Object, int);
71 extern void float_to_string(char*, fpfloat, int);
72
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 *). */
77
78 typedef struct Lisp_Float Lisp_Float;
79 struct Lisp_Float {
80         struct lrecord_header lheader;
81         union {
82                 fpfloat fpf;
83                 struct Lisp_Float *unused_next_;
84         } data;
85 };
86
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)
93
94 #define float_data(f)           ((f)->data.fpf)
95 #define XFLOAT_DATA(x)          float_data(XFLOAT(x))
96 #define XFLOATINT(n)            extract_float(n)
97
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;
106
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);
112
113 #include "ent-inf.h"
114 #include "ent-strflt.h"
115
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
122 #endif
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
129 #endif
130
131 \f
132 extern Lisp_Object Qrange_error;
133 EXFUN(Fsignal, 2);
134
135 extern_inline fpfloat ent_float(Lisp_Object);
136 #define extract_float   ent_float
137
138 extern_inline fpfloat
139 ent_float(Lisp_Object num)
140 {
141         num = ent_lift(num, FLOAT_T, NULL);
142         if (FLOATP(num))
143                 return XFLOAT_DATA(num);
144         else
145                 Fsignal(Qrange_error, num);
146         return 0.0f;
147 }
148
149 #endif /* INCLUDED_ent_float_h_ */