Update PUI to use ffi-curl
[sxemacs] / m4 / sxe-maths.m4
1 dnl sxe-maths.m4 -- Arithmetics and maths functions
2 dnl
3 dnl Copyright (C) 2005 - 2008 Sebastian Freundt
4 dnl Copyright (c) 2005 - 2008 Nelson Ferreira
5 dnl
6 dnl Redistribution and use in source and binary forms, with or without
7 dnl modification, are permitted provided that the following conditions
8 dnl are met:
9 dnl
10 dnl 1. Redistributions of source code must retain the above copyright
11 dnl    notice, this list of conditions and the following disclaimer.
12 dnl
13 dnl 2. Redistributions in binary form must reproduce the above copyright
14 dnl    notice, this list of conditions and the following disclaimer in the
15 dnl    documentation and/or other materials provided with the distribution.
16 dnl
17 dnl 3. Neither the name of the author nor the names of any contributors
18 dnl    may be used to endorse or promote products derived from this
19 dnl    software without specific prior written permission.
20 dnl
21 dnl THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
22 dnl IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 dnl WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 dnl DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 dnl FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 dnl CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 dnl SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 dnl BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 dnl WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30 dnl OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
31 dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 dnl
33 dnl This file is part of SXEmacs.
34
35 AC_DEFUN([_SXE_MATH_ASSIGN_IFELSE], [
36         dnl call it like so:
37         dnl _SXE_MATH_ASSIGN_IFELSE(<type>, <value>, <do-if>, <do-if-not>)
38         pushdef([type], [$1])
39         pushdef([value], [$2])
40
41         ## for math.h and limits.h
42         AC_REQUIRE([SXE_CHECK_MATHS_HEADERS])
43         AC_REQUIRE([SXE_CHECK_MATHS_TYPES])
44
45         AC_LINK_IFELSE([AC_LANG_PROGRAM([[
46 #if defined HAVE_MATH_H
47 # include <math.h>
48 #endif
49 #if defined HAVE_VALUES_H
50 # include <values.h>
51 #endif
52 #if defined HAVE_LIMITS_H
53 # include <limits.h>
54 #endif
55                 ]], [[]type[ __attribute__((unused)) __test_assign = ]value[];
56                 ])], [$3], [$4])
57
58         popdef([value])
59         popdef([type])
60 ])dnl _SXE_MATH_ASSIGN_IFELSE
61
62 AC_DEFUN([SXE_CHECK_MATHS_HEADERS], [dnl
63         ## just check for the bugger, no need to introduce new dependencies
64         SXE_CHECK_HEADERS([cfloat.h float.h inttypes.h limits.h math.h ieeefp.h])
65         SXE_CHECK_HEADERS([values.h])
66         SXE_CHECK_HEADERS([monetary.h])
67 ])dnl SXE_CHECK_MATHS_HEADERS
68
69
70 AC_DEFUN([SXE_CHECK_MATHS_TYPES], [dnl
71         AC_CHECK_TYPES([float])
72         AC_CHECK_TYPES([float_t])
73         AC_CHECK_TYPES([double])
74         AC_CHECK_TYPES([double_t])
75 ])dnl SXE_CHECK_MATHS_TYPES
76
77 AC_DEFUN([SXE_CHECK_MATHS_SYM], [dnl
78         dnl call it like
79         dnl SXE_CHECK_MATHS_SYM(<typeof_symbol>, <symbol>, [<if>, <if-not>])
80         ## defines HAVE_MATHS_<symbol> and
81         ## TYPEOF_MATHS_<symbol> (always defined) and
82         ## sxe_cv_maths_<symbol> as well as
83         ## have_maths_<symbol> (AC_SUBSTituted), and finally
84         ## sxe_cv_maths_typeof_<symbol> (also AC_SUBSTituted)
85         pushdef([typesym], [$1])
86         pushdef([sym], [$2])
87         pushdef([do_if], [$3])
88         pushdef([do_if_not], [$4])
89
90         AC_REQUIRE([SXE_CHECK_MATHS_HEADERS])
91         AC_REQUIRE([SXE_CHECK_MATHS_TYPES])
92
93         SXE_MSG_CHECKING([for ]sym[])
94         _SXE_MATH_ASSIGN_IFELSE([]typesym[], []sym[], [dnl yes case
95                 sxe_cv_maths_[]sym[]="yes"
96                 AC_DEFINE([HAVE_MATHS_]sym[], [1],
97                         [Whether ]sym[ is defined in math.h])
98                 AC_DEFINE([TYPEOF_MATHS_]sym[], []typesym[],
99                         [The type that seems to suit ]sym[])
100                 sxe_cv_maths_typeof_[]sym[]="[]typesym[]"
101                 ## do as the user pleases
102                 do_if
103                 ], [dnl no case
104                 sxe_cv_maths_[]sym[]="no"
105                 AC_DEFINE([TYPEOF_MATHS_]sym[], [void],
106                         [The type that seems to suit ]sym[])
107                 sxe_cv_maths_typeof_[]sym[]="void"
108                 ## do as the user pleases
109                 do_if_not
110                 ])
111         SXE_MSG_RESULT([$sxe_cv_maths_]sym[])
112         have_maths_[]sym[]="$sxe_cv_maths_[]sym[]"
113
114         AC_SUBST([have_maths_]sym[])
115         AC_SUBST([sxe_cv_maths_typeof_]sym[])
116
117         popdef([do_if])
118         popdef([do_if_not])
119         popdef([sym])
120         popdef([typesym])
121 ])dnl SXE_CHECK_MATHS_SYM
122
123
124 AC_DEFUN([SXE_MATHS_SHRT_MAX], [
125         SXE_CHECK_MATHS_SYM([short int], [SHRT_MAX], [$1], [$2])
126 ])dnl SXE_MATHS_SHRT_MAX
127
128 AC_DEFUN([SXE_MATHS_SHRT_MIN], [
129         SXE_CHECK_MATHS_SYM([short int], [SHRT_MIN], [$1], [$2])
130 ])dnl SXE_MATHS_SHRT_MIN
131
132 AC_DEFUN([SXE_MATHS_MAXSHORT], [
133         SXE_CHECK_MATHS_SYM([short int], [MAXSHORT], [$1], [$2])
134 ])dnl SXE_MATHS_MAXSHORT
135
136 AC_DEFUN([SXE_MATHS_MINSHORT], [
137         SXE_CHECK_MATHS_SYM([short int], [MINSHORT], [$1], [$2])
138 ])dnl SXE_MATHS_MINSHORT
139
140
141 AC_DEFUN([SXE_MATHS_INT_MAX], [
142         SXE_CHECK_MATHS_SYM([int], [INT_MAX], [$1], [$2])
143 ])dnl SXE_MATHS_INT_MAX
144
145 AC_DEFUN([SXE_MATHS_INT_MIN], [
146         SXE_CHECK_MATHS_SYM([int], [INT_MIN], [$1], [$2])
147 ])dnl SXE_MATHS_INT_MIN
148
149 AC_DEFUN([SXE_MATHS_MAXINT], [
150         SXE_CHECK_MATHS_SYM([int], [MAXINT], [$1], [$2])
151 ])dnl SXE_MATHS_MAXINT
152
153 AC_DEFUN([SXE_MATHS_MININT], [
154         SXE_CHECK_MATHS_SYM([int], [MININT], [$1], [$2])
155 ])dnl SXE_MATHS_MININT
156
157
158 AC_DEFUN([SXE_MATHS_LONG_MAX], [
159         SXE_CHECK_MATHS_SYM([long int], [LONG_MAX], [$1], [$2])
160 ])dnl SXE_MATHS_LONG_MAX
161
162 AC_DEFUN([SXE_MATHS_LONG_MIN], [
163         SXE_CHECK_MATHS_SYM([long int], [LONG_MIN], [$1], [$2])
164 ])dnl SXE_MATHS_LONG_MIN
165
166 AC_DEFUN([SXE_MATHS_MAXLONG], [
167         SXE_CHECK_MATHS_SYM([long int], [MAXLONG], [$1], [$2])
168 ])dnl SXE_MATHS_MAXLONG
169
170 AC_DEFUN([SXE_MATHS_MINLONG], [
171         SXE_CHECK_MATHS_SYM([long int], [MINLONG], [$1], [$2])
172 ])dnl SXE_MATHS_MINLONG
173
174
175 AC_DEFUN([SXE_MATHS_FLT_MAX], [
176         SXE_CHECK_MATHS_SYM([float], [FLT_MAX], [$1], [$2])
177 ])dnl SXE_MATHS_FLT_MAX
178
179 AC_DEFUN([SXE_MATHS_FLT_MIN], [
180         SXE_CHECK_MATHS_SYM([float], [FLT_MIN], [$1], [$2])
181 ])dnl SXE_MATHS_FLT_MIN
182
183 AC_DEFUN([SXE_MATHS_MAXFLOAT], [
184         SXE_CHECK_MATHS_SYM([float], [MAXFLOAT], [$1], [$2])
185 ])dnl SXE_MATHS_MAXFLOAT
186
187 AC_DEFUN([SXE_MATHS_MINFLOAT], [
188         SXE_CHECK_MATHS_SYM([float], [MINFLOAT], [$1], [$2])
189 ])dnl SXE_MATHS_MINFLOAT
190
191 AC_DEFUN([SXE_MATHS_FLT_MAX_EXP], [
192         SXE_CHECK_MATHS_SYM([float], [FLT_MAX_EXP], [$1], [$2])
193 ])dnl SXE_MATHS_FLT_MAX_EXP
194
195 AC_DEFUN([SXE_MATHS_FLT_MIN_EXP], [
196         SXE_CHECK_MATHS_SYM([float], [FLT_MIN_EXP], [$1], [$2])
197 ])dnl SXE_MATHS_FLT_MIN_EXP
198
199 AC_DEFUN([SXE_MATHS_FMAXEXP], [
200         SXE_CHECK_MATHS_SYM([float], [FMAXEXP], [$1], [$2])
201 ])dnl SXE_MATHS_FMAXEXP
202
203 AC_DEFUN([SXE_MATHS_FMINEXP], [
204         SXE_CHECK_MATHS_SYM([float], [FMINEXP], [$1], [$2])
205 ])dnl SXE_MATHS_FMINEXP
206
207
208 AC_DEFUN([SXE_MATHS_DBL_MAX], [
209         SXE_CHECK_MATHS_SYM([double], [DBL_MAX], [$1], [$2])
210 ])dnl SXE_MATHS_DBL_MAX
211
212 AC_DEFUN([SXE_MATHS_DBL_MIN], [
213         SXE_CHECK_MATHS_SYM([double], [DBL_MIN], [$1], [$2])
214 ])dnl SXE_MATHS_DBL_MIN
215
216 AC_DEFUN([SXE_MATHS_MAXDOUBLE], [
217         SXE_CHECK_MATHS_SYM([double], [MAXDOUBLE], [$1], [$2])
218 ])dnl SXE_MATHS_MAXDOUBLE
219
220 AC_DEFUN([SXE_MATHS_MINDOUBLE], [
221         SXE_CHECK_MATHS_SYM([double], [MINDOUBLE], [$1], [$2])
222 ])dnl SXE_MATHS_MINDOUBLE
223
224 AC_DEFUN([SXE_MATHS_DBL_MAX_EXP], [
225         SXE_CHECK_MATHS_SYM([double], [DBL_MAX_EXP], [$1], [$2])
226 ])dnl SXE_MATHS_DBL_MAX_EXP
227
228 AC_DEFUN([SXE_MATHS_DBL_MIN_EXP], [
229         SXE_CHECK_MATHS_SYM([double], [DBL_MIN_EXP], [$1], [$2])
230 ])dnl SXE_MATHS_DBL_MIN_EXP
231
232 AC_DEFUN([SXE_MATHS_DMAXEXP], [
233         SXE_CHECK_MATHS_SYM([double], [DMAXEXP], [$1], [$2])
234 ])dnl SXE_MATHS_DMAXEXP
235
236 AC_DEFUN([SXE_MATHS_DMINEXP], [
237         SXE_CHECK_MATHS_SYM([double], [DMINEXP], [$1], [$2])
238 ])dnl SXE_MATHS_DMINEXP
239
240
241 AC_DEFUN([SXE_MATHS_LDBL_MAX], [
242         SXE_CHECK_MATHS_SYM([long double], [LDBL_MAX], [$1], [$2])
243 ])dnl SXE_MATHS_LDBL_MAX
244
245 AC_DEFUN([SXE_MATHS_LDBL_MIN], [
246         SXE_CHECK_MATHS_SYM([long double], [LDBL_MIN], [$1], [$2])
247 ])dnl SXE_MATHS_LDBL_MIN
248
249
250 AC_DEFUN([SXE_MATHS_INFINITY], [
251         SXE_CHECK_MATHS_SYM([float_t], [INFINITY], [$1], [$2])
252 ])dnl SXE_MATHS_INFINITY
253
254 AC_DEFUN([SXE_MATHS_NAN], [
255         SXE_CHECK_MATHS_SYM([float_t], [NAN], [$1], [$2])
256 ])dnl SXE_MATHS_NAN
257
258
259 dnl compound thing
260 AC_DEFUN([SXE_CHECK_MATHS_VALUES], [dnl
261         SXE_MATHS_SHRT_MAX
262         SXE_MATHS_SHRT_MIN
263         SXE_MATHS_MAXSHORT
264         SXE_MATHS_MINSHORT
265
266         SXE_MATHS_INT_MAX
267         SXE_MATHS_INT_MIN
268         SXE_MATHS_MAXINT
269         SXE_MATHS_MININT
270
271         SXE_MATHS_LONG_MAX
272         SXE_MATHS_LONG_MIN
273         SXE_MATHS_MAXLONG
274         SXE_MATHS_MINLONG
275
276         SXE_MATHS_FLT_MAX
277         SXE_MATHS_FLT_MIN
278         SXE_MATHS_MAXFLOAT
279         SXE_MATHS_MINFLOAT
280         SXE_MATHS_FLT_MAX_EXP
281         SXE_MATHS_FLT_MIN_EXP
282         SXE_MATHS_FMAXEXP
283         SXE_MATHS_FMINEXP
284
285         SXE_MATHS_DBL_MAX
286         SXE_MATHS_DBL_MIN
287         SXE_MATHS_MAXDOUBLE
288         SXE_MATHS_MINDOUBLE
289         SXE_MATHS_DBL_MAX_EXP
290         SXE_MATHS_DBL_MIN_EXP
291         SXE_MATHS_DMAXEXP
292         SXE_MATHS_DMINEXP
293
294         SXE_MATHS_LDBL_MAX
295         SXE_MATHS_LDBL_MIN
296
297         SXE_MATHS_INFINITY
298         SXE_MATHS_NAN
299 ])dnl SXE_CHECK_MATHS_VALUES
300
301
302 AC_DEFUN([SXE_MATHS_FINITE], [
303         ## could be an ordinary function, at least it should be
304         AC_CHECK_FUNCS([finite])
305
306         SXE_MSG_CHECKING([for working finite])
307         _SXE_MATH_ASSIGN_IFELSE([float], [0.0; finit(__test_assign);],
308                 [sxe_cv_maths_finite="yes"], [sxe_cv_maths_finite="no"])
309         SXE_MSG_RESULT([$sxe_cv_maths_fpclassify])
310
311         if test "$sxe_cv_maths_finite" = "yes"; then
312                 AC_DEFINE_UNQUOTED([HAVE_MATHS_FINITE], [1],
313                         [Whether finite() is defined])
314                 $1
315         else
316                 :
317                 $2
318         fi
319 ])dnl SXE_MATHS_FINITE
320
321 AC_DEFUN([SXE_MATHS_FPCLASS], [
322         ## could be an ordinary function, at least it should be
323         AC_CHECK_FUNCS([fpclass])
324
325         SXE_MSG_CHECKING([for working fpclass])
326         _SXE_MATH_ASSIGN_IFELSE([float], [0.0; fpclass(__test_assign);],
327                 [sxe_cv_maths_fpclass="yes"], [sxe_cv_maths_fpclass="no"])
328         SXE_MSG_RESULT([$sxe_cv_maths_fpclass])
329
330         if test "$sxe_cv_maths_fpclass" = "yes"; then
331                 AC_DEFINE_UNQUOTED([HAVE_MATHS_FPCLASS], [1],
332                         [Whether fpclass() is defined])
333                 $1
334         else
335                 :
336                 $2
337         fi
338 ])dnl SXE_MATHS_FPCLASS
339
340 AC_DEFUN([SXE_MATHS_FPCLASSIFY], [
341         ## could be an ordinary function, at least it should be
342         AC_CHECK_FUNCS([fpclassify __fpclassifyf __fpclassify __fpclassifyl])
343
344         SXE_MSG_CHECKING([for working fpclassify])
345         _SXE_MATH_ASSIGN_IFELSE([float], [0.0; fpclassify(__test_assign);],
346                 [sxe_cv_maths_fpclassify="yes"], [sxe_cv_maths_fpclassify="no"])
347         SXE_MSG_RESULT([$sxe_cv_maths_fpclassify])
348
349         if test "$sxe_cv_maths_fpclassify" = "yes"; then
350                 AC_DEFINE_UNQUOTED([HAVE_MATHS_FPCLASSIFY], [1],
351                         [Whether fpclassify() is defined in math.h])
352                 $1
353         else
354                 :
355                 $2
356         fi
357 ])dnl SXE_MATHS_FPCLASSIFY
358
359 AC_DEFUN([SXE_MATHS_ISINF], [
360         ## could be an ordinary function, at least it should be
361         AC_CHECK_FUNCS([isinf __isinff __isinf __isinfl])
362
363         SXE_MSG_CHECKING([for working isinf])
364         _SXE_MATH_ASSIGN_IFELSE([float], [0.0; isinf(__test_assign);],
365                 [sxe_cv_maths_isinf="yes"], [sxe_cv_maths_isinf="no"])
366         SXE_MSG_RESULT([$sxe_cv_maths_isinf])
367
368         if test "$sxe_cv_maths_isinf" = "yes"; then
369                 AC_DEFINE_UNQUOTED([HAVE_MATHS_ISINF], [1],
370                         [Whether isinf() is defined in math.h])
371                 $1
372         else
373                 :
374                 $2
375         fi
376 ])dnl SXE_MATH_ISINF
377
378 AC_DEFUN([SXE_MATHS_ISNAN], [
379         ## could be an ordinary function, at least it should be
380         AC_CHECK_FUNCS([isnan __isnanf __isnan __isnanl])
381
382         SXE_MSG_CHECKING([for working isnan])
383         _SXE_MATH_ASSIGN_IFELSE([float], [0.0; isnan(__test_assign);],
384                 [sxe_cv_maths_isnan="yes"], [sxe_cv_maths_isnan="no"])
385         SXE_MSG_RESULT([$sxe_cv_maths_isnan])
386
387         if test "$sxe_cv_maths_isnan" = "yes"; then
388                 AC_DEFINE_UNQUOTED([HAVE_MATHS_ISNAN], [1],
389                         [Whether isnan() is defined in math.h])
390                 $1
391         else
392                 :
393                 $2
394         fi
395 ])dnl SXE_MATH_ISNAN
396
397 AC_DEFUN([SXE_MATHS_SIGNBIT], [
398         ## could be an ordinary function, at least it should be
399         AC_CHECK_FUNCS([signbit __signbitf __signbit __signbitl])
400
401         SXE_MSG_CHECKING([for working signbit])
402         _SXE_MATH_ASSIGN_IFELSE([float], [-1.0; signbit(__test_assign);],
403                 [sxe_cv_maths_signbit="yes"], [sxe_cv_maths_signbit="no"])
404         SXE_MSG_RESULT([$sxe_cv_maths_signbit])
405
406         if test "$sxe_cv_maths_signbit" = "yes"; then
407                 AC_DEFINE([HAVE_MATHS_SIGNBIT], [1],
408                         [Whether signbit() is defined in math.h])
409                 $1
410         else
411                 :
412                 $2
413         fi
414 ])dnl SXE_MATH_SIGNBIT
415
416
417 dnl
418 dnl all the ENT stuff
419 dnl =================
420 AC_DEFUN([SXE_CHECK_ENT_MSG], [dnl
421         AS_MESSAGE([checking for Enhanced Number Types])
422 ])dnl SXE_CHECK_ENT_MSG
423
424 AC_DEFUN([SXE_CHECK_ENT], [dnl
425         AC_REQUIRE([SXE_CHECK_ENT_MSG])
426
427         SXE_CHECK_GMP
428         dnl SXE_CHECK_BSDMP
429         SXE_CHECK_MPFR
430         SXE_CHECK_MPC
431         SXE_CHECK_ECM
432
433         ## instead we define the following
434         with_ent_mp="no"
435         sxe_cv_feat_bsdmp="no"
436 ])dnl SXE_CHECK_ENT
437
438 dnl
439 dnl GMP
440 dnl ===
441 AC_DEFUN([SXE_CHECK_GMP], [dnl
442         ## call like this SXE_CHECK_GMP([<if-found>], [<if-not-found>])
443         ## defines HAVE_GMP, HAVE_MPZ, HAVE_MPQ, HAVE_MPF
444         pushdef([ACTION_IF_FOUND], [$1])
445         pushdef([ACTION_IF_NOT_FOUND], [$2])
446
447         AC_CACHE_CHECK([for GNU mp multi-precision arithmetics support],
448                 [sxe_cv_feat_gmp], [_SXE_CHECK_GMP])
449
450         if test "$sxe_cv_feat_gmp" = "yes"; then
451                 AC_DEFINE([HAVE_GMP], [1],
452                         [Whether mp arithmetics come from GNU MP (GMP)])
453                 ACTION_IF_FOUND
454                 :
455         else
456                 ACTION_IF_NOT_FOUND
457                 :
458         fi
459
460         popdef([ACTION_IF_FOUND])
461         popdef([ACTION_IF_NOT_FOUND])
462 ])dnl SXE_CHECK_GMP
463
464 AC_DEFUN([_SXE_CHECK_GMP], [dnl
465         SXE_DUMP_LIBS
466         CPPFLAGS="$CPPFLAGS $ENT_CPPFLAGS"
467         LDFLAGS="$CPPFLAGS $ENT_LDFLAGS"
468         LIBS="$LIBS $ENT_LIBS"
469
470         AC_REQUIRE([SXE_CHECK_GMP_HEADERS])
471         AC_REQUIRE([SXE_CHECK_GMP_LIBS])
472         SXE_RESTORE_LIBS
473
474         if test "$ac_cv_header_gmp_h" = "yes" -a \
475                 "$ac_cv_lib_gmp___gmpz_init" = "yes" -a \
476                 "$ac_cv_lib_gmp___gmpq_init" = "yes" -a \
477                 "$ac_cv_lib_gmp___gmpf_init" = "yes"; then
478                 sxe_cv_feat_gmp="yes"
479                 AC_DEFINE([HAVE_MPZ], [1], [Description here!])
480                 AC_DEFINE([HAVE_MPQ], [1], [Description here!])
481                 AC_DEFINE([HAVE_MPF], [1], [Description here!])
482                 GMP_LIBS="-lgmp"
483         else
484                 sxe_cv_feat_gmp="no"
485         fi
486 ])dnl _SXE_CHECK_GMP
487
488 AC_DEFUN([SXE_CHECK_GMP_HEADERS], [dnl
489         AC_CHECK_HEADERS([gmp.h])
490 ])dnl SXE_CHECK_GMP_HEADERS
491
492 AC_DEFUN([SXE_CHECK_GMP_LIBS], [dnl
493         AC_CHECK_LIB([gmp], [__gmpz_init], [:])
494         AC_CHECK_LIB([gmp], [__gmpq_init], [:])
495         AC_CHECK_LIB([gmp], [__gmpf_init], [:])
496 ])dnl SXE_CHECK_GMP_LIBS
497
498 dnl
499 dnl BSD-MP
500 dnl ======
501 AC_DEFUN([SXE_CHECK_BSDMP], [dnl
502         ## call like this SXE_CHECK_BSDMP([<if-found>], [<if-not-found>])
503         ## defines HAVE_BSDMP, HAVE_MPZ
504         pushdef([ACTION_IF_FOUND], [$1])
505         pushdef([ACTION_IF_NOT_FOUND], [$2])
506
507         AC_CACHE_CHECK([for BSD mp multi-precision arithmetics support],
508                 [sxe_cv_feat_bsdmp], [_SXE_CHECK_BSDMP])
509
510         if test "$sxe_cv_feat_bsdmp" = "yes"; then
511                 AC_DEFINE([HAVE_BSDMP], [1],
512                         [Whether mp-arithmetics come from BSD mp library])
513                 AC_DEFINE([HAVE_MPZ], [1], [Description here!])
514                 ACTION_IF_FOUND
515                 :
516         else
517                 ACTION_IF_NOT_FOUND
518                 :
519         fi
520
521         popdef([ACTION_IF_FOUND])
522         popdef([ACTION_IF_NOT_FOUND])
523 ])dnl SXE_CHECK_BSDMP
524
525 AC_DEFUN([_SXE_CHECK_BSDMP], [dnl
526         SXE_DUMP_LIBS
527         CPPFLAGS="$CPPFLAGS $ENT_CPPFLAGS"
528         LDFLAGS="$CPPFLAGS $ENT_LDFLAGS"
529         LIBS="$LIBS $ENT_LIBS"
530
531         AC_REQUIRE([SXE_CHECK_BSDMP_HEADERS])
532         AC_REQUIRE([SXE_CHECK_BSDMP_LIBS])
533         AC_REQUIRE([SXE_CHECK_BSDMP_FUNCS])
534         SXE_RESTORE_LIBS
535
536         if test "$ac_cv_header_mp_h" = "yes" -a \
537                 "$ac_cv_lib_mp_mp_mfree" = "yes"; then
538                 AC_DEFINE([MP_PREFIX], [1], [Description here!])
539                 sxe_cv_feat_bsdmp="yes"
540                 BSDMP_LIBS="-lmp"
541         elif test "$ac_cv_header_mp_h" = "yes" -a \
542                 "$ac_cv_lib_mp_mfree" = "yes"; then
543                 sxe_cv_feat_bsdmp="yes"
544                 BSDMP_LIBS="-lmp"
545         else
546                 sxe_cv_feat_bsdmp="no"
547         fi
548 ])dnl _SXE_CHECK_BSDMP
549
550 AC_DEFUN([SXE_CHECK_BSDMP_HEADERS], [dnl
551         AC_CHECK_HEADERS([mp.h])
552 ])dnl SXE_CHECK_BSDMP_HEADERS
553
554 AC_DEFUN([SXE_CHECK_BSDMP_LIBS], [dnl
555         AC_CHECK_LIB([mp], [mp_mfree], [:])
556         AC_CHECK_LIB([mp], [mfree], [:])
557         ## also try to find these in -lcrypto
558         ## we don't do this now because of weird interdependencies
559         ## with openssl support
560 ])dnl SXE_CHECK_BSDMP_LIBS
561
562 AC_DEFUN([SXE_CHECK_BSDMP_FUNCS], [dnl
563         AC_CHECK_FUNCS([mp_move move])
564 ])dnl SXE_CHECK_ENT_BSDMP
565
566
567 dnl
568 dnl MPFR
569 dnl ====
570 AC_DEFUN([SXE_CHECK_MPFR], [dnl
571         ## call like this SXE_CHECK_MPFR([<if-found>], [<if-not-found>])
572         ## defines HAVE_MPFR
573         pushdef([ACTION_IF_FOUND], [$1])
574         pushdef([ACTION_IF_NOT_FOUND], [$2])
575
576         AC_CACHE_CHECK([for mpfr real number support],
577                 [sxe_cv_feat_mpfr], [_SXE_CHECK_MPFR])
578
579         if test "$sxe_cv_feat_mpfr" = "yes"; then
580                 AC_DEFINE([HAVE_MPFR], [1], [Whether mpfr support is doable])
581                 ACTION_IF_FOUND
582                 :
583         else
584                 ACTION_IF_NOT_FOUND
585                 :
586         fi
587
588         popdef([ACTION_IF_FOUND])
589         popdef([ACTION_IF_NOT_FOUND])
590 ])dnl SXE_CHECK_MPFR
591
592 AC_DEFUN([_SXE_CHECK_MPFR], [dnl
593         SXE_DUMP_LIBS
594         CPPFLAGS="$CPPFLAGS $ENT_CPPFLAGS"
595         LDFLAGS="$CPPFLAGS $ENT_LDFLAGS"
596         LIBS="$LIBS $ENT_LIBS"
597
598         AC_REQUIRE([SXE_CHECK_MPFR_HEADERS])
599         AC_REQUIRE([SXE_CHECK_MPFR_LIBS])
600         SXE_RESTORE_LIBS
601
602         if test "$ac_cv_header_mpfr_h" = "yes" -a \
603                 "$ac_cv_lib_mpfr_mpfr_init" = "yes" -a \
604                 "$ac_cv_lib_mpfr_mpfr_equal_p" = "yes" -a \
605                 "$ac_cv_lib_mpfr_mpfr_atan2" = "yes" -a \
606                 "$ac_cv_lib_mpfr_mpfr_exp10" = "yes" -a \
607                 "$ac_cv_lib_mpfr_mpfr_sec" = "yes"; then
608                 sxe_cv_feat_mpfr="yes"
609                 MPFR_LIBS="-lmpfr"
610         elif test "$ac_cv_header_mpfr_h" = "yes" -a \
611                 "$ac_cv_lib_mpfr_mpfr_init" = "yes"; then
612                 AS_MESSAGE([ENT: MPFR is too old. dnl
613 Consider http://www.mpfr.org and fetch a later one.])
614                 AS_MESSAGE([ENT: Also note that the MPFR supplied by GMP dnl
615 cannot be used with SXEmacs.])
616                 sxe_cv_feat_mpfr="no"
617         else
618                 sxe_cv_feat_mpfr="no"
619         fi
620 ])dnl _SXE_CHECK_MPFR
621
622 AC_DEFUN([SXE_CHECK_MPFR_HEADERS], [dnl
623         AC_CHECK_HEADERS([mpfr.h])
624 ])dnl SXE_CHECK_MPFR_HEADERS
625
626 AC_DEFUN([SXE_CHECK_MPFR_LIBS], [dnl
627         AC_CHECK_LIB([mpfr], [mpfr_init], [:])
628         ## do not accept this old MPFR distributed with GMP
629         ## to do this, we make sure to find the following functions in
630         ## libmpfr as they are known to be missing in the GMP-supplied
631         ## version
632         AC_CHECK_LIB([mpfr], [mpfr_equal_p], [:])
633         ## check for trigonometrical and exponential funs
634         AC_CHECK_LIB([mpfr], [mpfr_atan2], [:])
635         AC_CHECK_LIB([mpfr], [mpfr_sec], [:])
636         AC_CHECK_LIB([mpfr], [mpfr_exp10], [:])
637 ])dnl SXE_CHECK_MPFR
638
639 dnl
640 dnl MPC
641 dnl ===
642 AC_DEFUN([SXE_CHECK_MPC], [dnl
643         ## call like this SXE_CHECK_MPC([<if-found>], [<if-not-found>])
644         ## defines HAVE_MPC
645         pushdef([ACTION_IF_FOUND], [$1])
646         pushdef([ACTION_IF_NOT_FOUND], [$2])
647
648         AC_REQUIRE([SXE_CHECK_MPFR])
649         AC_CACHE_CHECK([for libmpc complex number support],
650                 [sxe_cv_feat_mpc], [_SXE_CHECK_MPC])
651
652         if test "$sxe_cv_feat_mpc" = "yes"; then
653                 AC_DEFINE([HAVE_MPC], [1], [Whether mpc support is available])
654                 ACTION_IF_FOUND
655                 :
656         else
657                 ACTION_IF_NOT_FOUND
658                 :
659         fi
660
661         popdef([ACTION_IF_FOUND])
662         popdef([ACTION_IF_NOT_FOUND])
663 ])dnl SXE_CHECK_MPC
664
665 AC_DEFUN([_SXE_CHECK_MPC], [dnl
666         SXE_DUMP_LIBS
667         CPPFLAGS="$CPPFLAGS $ENT_CPPFLAGS"
668         LDFLAGS="$CPPFLAGS $ENT_LDFLAGS"
669         LIBS="$LIBS $ENT_LIBS"
670
671         AC_REQUIRE([SXE_CHECK_MPC_HEADERS])
672         AC_REQUIRE([SXE_CHECK_MPC_LIBS])
673         SXE_RESTORE_LIBS
674
675         if test "$ac_cv_lib_mpc_mpc_init" = "yes"; then
676                 AC_DEFINE([HAVE_MPC_INIT], [1], [Whether simple mpc_init is available])
677         fi
678         if test "$ac_cv_lib_mpc_mpc_set_ui_fr" = "yes"; then
679                 AC_DEFINE([HAVE_MPC_SET_UI_FR], [1], [Whether simple mpc_set_ui_fr is available])
680         fi
681         if test "$ac_cv_lib_mpc_mpc_init" = "yes" -o \
682                 "$ac_cv_lib_mpc_mpc_init2" = "yes"; then
683                 mpc_can_be_initted="yes"
684         fi
685         if test "$ac_cv_header_mpc_h" = "yes" -a \
686                 "$mpc_can_be_initted" = "yes" -a \
687                 "$mpc_doth_need_mpfr" = "yes"; then
688                 sxe_cv_feat_mpc="yes"
689                 MPC_LIBS="-lmpfr -lmpc"
690         elif test "$ac_cv_header_mpc_h" = "yes" -a \
691                 "$mpc_can_be_initted" = "yes" -a \
692                 "$mpc_doth_need_mpfr" = "no"; then
693                 sxe_cv_feat_mpc="yes"
694                 MPC_LIBS="-lmpc"
695         else
696                 sxe_cv_feat_mpc="no"
697         fi
698 ])dnl _SXE_CHECK_MPC
699
700 AC_DEFUN([SXE_CHECK_MPC_HEADERS], [dnl
701         AC_REQUIRE([SXE_CHECK_MPFR_HEADERS])
702         if test "$ac_cv_header_mpfr_h" = "yes"; then
703                 AC_CHECK_HEADERS([mpc.h], [:], [:], [#include <mpfr.h>])
704         else
705                 ## try without mpfr.h, but this is definitely going to fail
706                 ## unless you're a developer of mpc ...
707                 ## ... and in that case: Fix teh MPC build chain, Andreas!!!
708                 AC_CHECK_HEADERS([mpc.h])
709         fi
710 ])dnl SXE_CHECK_MPC_HEADERS
711
712 AC_DEFUN([SXE_CHECK_MPC_LIBS], [dnl
713         AC_REQUIRE([SXE_CHECK_MPFR_LIBS])
714         if test "$ac_cv_lib_mpfr_mpfr_init" = "yes"; then
715                 AC_CHECK_LIB([mpc], [mpc_init], [:], [:], [-lmpfr])
716                 AC_CHECK_LIB([mpc], [mpc_init2], [:], [:], [-lmpfr])
717                 AC_CHECK_LIB([mpc], [mpc_set_ui_fr], [:], [:], [-lmpfr])
718                 mpc_doth_need_mpfr="yes"
719         else
720                 ## try without mpfr.h, but this is definitely going to fail
721                 ## unless you're a developer of mpc ...
722                 ## ... and in that case: Fix the MPC build chain, Andreas!!!
723                 AC_CHECK_LIB([mpc], [mpc_init], [:])
724                 AC_CHECK_LIB([mpc], [mpc_init2], [:])
725                 AC_CHECK_LIB([mpc], [mpc_set_ui_fr], [:])
726                 mpc_doth_need_mpfr="no"
727         fi
728 ])dnl SXE_CHECK_MPC_LIBS
729
730
731 AC_DEFUN([SXE_CHECK_ECM], [dnl
732         ## call like this SXE_CHECK_ECM([<if-found>], [<if-not-found>])
733         ## defines HAVE_ECM
734         pushdef([ACTION_IF_FOUND], [$1])
735         pushdef([ACTION_IF_NOT_FOUND], [$2])
736
737         AC_REQUIRE([SXE_CHECK_GMP])
738         AC_CACHE_CHECK([for ecm factorisation support],
739                 [sxe_cv_feat_ecm], [_SXE_CHECK_ECM])
740
741         if test "$sxe_cv_feat_ecm" = "yes"; then
742                 AC_DEFINE([HAVE_ECM], [1], [Whether ecm support is doable])
743                 ACTION_IF_FOUND
744                 :
745         else
746                 ACTION_IF_NOT_FOUND
747                 :
748         fi
749
750         popdef([ACTION_IF_FOUND])
751         popdef([ACTION_IF_NOT_FOUND])
752 ])dnl SXE_CHECK_ECM
753
754 AC_DEFUN([_SXE_CHECK_ECM], [dnl
755         SXE_DUMP_LIBS
756         ## ecm often needs GMP and is even more often linked statically
757         ## so we just pump all the ENT stuff into our slots here
758         CPPFLAGS="$CPPFLAGS $ENT_CPPFLAGS"
759         LDFLAGS="$CPPFLAGS $ENT_LDFLAGS"
760         LIBS="$LIBS $ENT_LIBS"
761
762         AC_REQUIRE([SXE_CHECK_ECM_HEADERS])
763         AC_REQUIRE([SXE_CHECK_ECM_LIBS])
764         SXE_RESTORE_LIBS
765
766         if test "$ac_cv_header_ecm_h" = "yes" -a \
767                 "$ac_cv_lib_ecm_ecm_init" = "yes" -a \
768                 "$ecm_doth_need_gmp" = "yes"; then
769                 sxe_cv_feat_ecm="yes"
770                 ECM_LIBS="-lgmp -lecm"
771         elif test "$ac_cv_header_ecm_h" = "yes" -a \
772                 "$ac_cv_lib_ecm_ecm_init" = "yes" -a \
773                 "$ecm_doth_need_gmp" = "no"; then
774                 sxe_cv_feat_ecm="yes"
775                 ECM_LIBS="-lecm"
776         else
777                 sxe_cv_feat_ecm="no"
778         fi
779 ])dnl _SXE_CHECK_ECM
780
781 AC_DEFUN([SXE_CHECK_ECM_HEADERS], [dnl
782         AC_REQUIRE([SXE_CHECK_GMP_HEADERS])
783         if test "$ac_cv_header_gmp_h" = "yes"; then
784                 AC_CHECK_HEADERS([ecm.h], [:], [:], [#include <gmp.h>])
785                 ecm_doth_need_gmp="yes"
786         else
787                 ## try without ... oughta work, too
788                 AC_CHECK_HEADERS([ecm.h])
789                 ecm_doth_need_gmp="no"
790         fi
791 ])dnl SXE_CHECK_ECM_HEADERS
792
793 AC_DEFUN([SXE_CHECK_ECM_LIBS], [dnl
794         AC_REQUIRE([SXE_CHECK_GMP_LIBS])
795         if test "$ac_cv_lib_gmp___gmpz_init" = "yes"; then
796                 AC_CHECK_LIB([ecm], [ecm_init], [:], [:], [-lgmp])
797                 ecm_doth_need_gmp="yes"
798         else
799                 ## try without ... could work if the user linked a
800                 ## static gmp into libecm.a
801                 AC_CHECK_LIB([ecm], [ecm_init], [:])
802                 ecm_doth_need_gmp="no"
803         fi
804 ])dnl SXE_CHECK_ECM_LIBS
805
806
807 AC_DEFUN([SXE_CHECK_CLEAN_FLOATOPS], [dnl
808         ## call like this SXE_CHECK_CLEAN_FLOATOPS([<if-so>], [<if-not>])
809         pushdef([ACTION_IF_TRUE], [$1])
810         pushdef([ACTION_IF_FALSE], [$2])
811
812         dnl test if floats are clean
813         AC_CHECK_FUNCS([strtof])
814         AC_CHECK_FUNCS([strtod])
815         AC_CHECK_FUNCS([strtold])
816         AC_CHECK_FUNCS([strtol])
817         AC_CHECK_FUNCS([strtoll])
818         AC_CHECK_FUNCS([strtoq])
819
820         SXE_MATHS_FPCLASSIFY
821         SXE_MATHS_FPCLASS
822         SXE_MATHS_FINITE
823         SXE_MATHS_ISINF
824         SXE_MATHS_ISNAN
825         SXE_MATHS_SIGNBIT
826
827         floatops_clean_p="no"
828         SXE_MSG_CHECKING([for clean float operations])
829
830         AC_DEFINE_UNQUOTED([fpfloat_cand], [$fpfloat], [Temporary.])
831         AC_DEFINE_UNQUOTED([fpfloat_cand_double_p],
832                 [${fpfloat_double_p:-0}], [Temporary.])
833         AC_DEFINE_UNQUOTED([fpfloat_cand_long_double_p],
834                 [${fpfloat_long_double_p:-0}], [Temporary.])
835
836         AC_RUN_IFELSE([AC_LANG_SOURCE([[
837 #include <math.h>
838 #include <values.h>
839 #include <stdlib.h>
840 #include <stdio.h>
841 #include <string.h>
842
843 typedef fpfloat_cand fpfloat;
844 #define fpfloat_double_p fpfloat_cand_double_p
845 #define fpfloat_long_double_p fpfloat_cand_long_double_p
846
847 #include "$sxe_srcdir/src/ent-inf.h"
848 #include "$sxe_srcdir/src/ent-strflt.h"
849
850 int main(int c, char **v)
851 {
852         fpfloat_cand o4;
853         fpfloat_cand surprise;
854
855         surprise = str_to_fpfloat("0.0") + (o4 = str_to_fpfloat("1.4"));
856
857         if (surprise == o4)
858 #if fpfloat_cand_long_double_p
859         {
860                 fpfloat_cand gtdouble_s = str_to_fpfloat("1.0e+513");
861                 fpfloat_cand gtdouble_l = 1.0e+513L;
862                 char         buf[1024];
863
864                 if ( ENT_FLOAT_INDEFINITE_P(gtdouble_l) )
865                         return 0;
866                 *buf=buf[1023]='\0';
867                 snprintf(buf,1023,"%Lf",gtdouble_s);
868                 if ( ! strncasecmp("inf",buf,3 ) )
869                         return 1;
870                 if ( ! strncasecmp("nan",buf,3 ) )
871                         return 1;
872                 snprintf(buf,1023,"%Lf",gtdouble_l);
873                 if ( ! strncasecmp("inf",buf,3 ) )
874                         return 1;
875                 if ( ! strncasecmp("nan",buf,3 ) )
876                         return 1;
877                 return 0;
878         }
879 #else
880                 return 0;
881 #endif
882         else
883                 return 1;
884 }
885         ]])], [
886                 ./conftest dummy_arg; floatop_status=$?;
887                 if test "$floatop_status" = "0"; then
888                         ACTION_IF_TRUE
889                         AC_DEFINE([HAVE_CLEAN_FLOATOPS], [1], [Description here!])
890                         floatops_clean_p="yes"
891                 else
892                         ACTION_IF_FALSE
893                         :
894                 fi],
895                 [ACTION_IF_FALSE], [ACTION_IF_FALSE])
896
897         SXE_MSG_RESULT([$floatops_clean_p])
898
899         popdef([ACTION_IF_TRUE])
900         popdef([ACTION_IF_FALSE])
901 ])dnl SXE_CHECK_CLEAN_FLOATOPS
902
903
904 dnl sxe-maths.m4 ends here