This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Configure: scan for truncl.
[metaconfig.git] / U / perl / d_modfl.U
CommitLineData
d5e0373c
JH
1?RCS: $Id$
2?RCS:
3?RCS: Copyright (c) 2000 Jarkko Hietaniemi
4?RCS:
5?RCS: You may distribute under the terms of either the GNU General Public
6?RCS: License or the Artistic License, as specified in the README file.
7?RCS:
a7eb1db8 8?MAKE:d_modfl d_modflproto d_modfl_pow32_bug: Inlibc Compile Hasproto cat \
2cb64bf6 9 rm_try test sPRIfldbl d_longdbl osname gccversion ccflags run \
3cf920b4 10 uselongdouble i_math \
7668538f
MBT
11 d_sqrtl d_aintl d_copysignl d_ilogbl d_scalbnl d_frexpl d_ldexpl \
12 d_truncl
d5e0373c
JH
13?MAKE: -pick add $@ %<
14?S:d_modfl:
15?S: This variable conditionally defines the HAS_MODFL symbol, which
16?S: indicates to the C program that the modfl() routine is available.
17?S:.
a7eb1db8 18?S:d_modflproto:
554af3fc
MB
19?S: This symbol, if defined, indicates that the system provides
20?S: a prototype for the modfl() function. Otherwise, it is up
21?S: to the program to supply one. C99 says it should be
22?S: long double modfl(long double, long double *);
a7eb1db8 23?S:.
73fce044
JH
24?S:d_modfl_pow32_bug:
25?S: This variable conditionally defines the HAS_MODFL_POW32_BUG symbol,
26?S: which indicates that modfl() is broken for long doubles >= pow(2, 32).
27?S: For example from 4294967303.150000 one would get 4294967302.000000
28?S: and 1.150000. The bug has been seen in certain versions of glibc,
29?S: release 2.2.2 is known to be okay.
30?S:.
d5e0373c
JH
31?C:HAS_MODFL:
32?C: This symbol, if defined, indicates that the modfl routine is
33?C: available to split a long double x into a fractional part f and
34?C: an integer part i such that |f| < 1.0 and (f + i) = x.
35?C:.
a7eb1db8 36?C:HAS_MODFL_PROTO:
554af3fc
MB
37?C: This symbol, if defined, indicates that the system provides
38?C: a prototype for the modfl() function. Otherwise, it is up
39?C: to the program to supply one.
a7eb1db8 40?C:.
73fce044
JH
41?C:HAS_MODFL_POW32_BUG:
42?C: This symbol, if defined, indicates that the modfl routine is
43?C: broken for long doubles >= pow(2, 32).
44?C: For example from 4294967303.150000 one would get 4294967302.000000
45?C: and 1.150000. The bug has been seen in certain versions of glibc,
46?C: release 2.2.2 is known to be okay.
47?C:.
d5e0373c 48?H:#$d_modfl HAS_MODFL /**/
554af3fc 49?H:#$d_modflproto HAS_MODFL_PROTO /**/
73fce044 50?H:#$d_modfl_pow32_bug HAS_MODFL_POW32_BUG /**/
d5e0373c 51?H:.
0065f4af
MB
52?T:foo saveccflags message
53?F:!try
bf7497fb 54?LINT:set d_modflproto
a4f5ff76 55?LINT:change ccflags
d5e0373c
JH
56: see if modfl exists
57set modfl d_modfl
58eval $inlibc
59
a7eb1db8
MB
60: see if prototype for modfl is available
61echo " "
3cf920b4 62set d_modflproto modfl $i_math math.h
a7eb1db8
MB
63eval $hasproto
64
73fce044
JH
65d_modfl_pow32_bug="$undef"
66
06bb3943
JH
67case "$d_longdbl$d_modfl" in
68$define$define)
69 $cat <<EOM
70Checking to see whether your modfl() is okay for large values...
71EOM
72$cat >try.c <<EOCP
2cb64bf6 73#include <math.h>
06bb3943 74#include <stdio.h>
a7eb1db8
MB
75EOCP
76if $test "X$d_modflproto" != "X$define"; then
77 $cat >>try.c <<EOCP
2cb64bf6 78/* Sigh. many current glibcs provide the function, but do not prototype it. */
a7eb1db8
MB
79long double modfl (long double, long double *);
80EOCP
81fi
82$cat >>try.c <<EOCP
06bb3943
JH
83int main() {
84 long double nv = 4294967303.15;
85 long double v, w;
2cb64bf6 86 v = modfl(nv, &w);
06bb3943
JH
87#ifdef __GLIBC__
88 printf("glibc");
89#endif
90 printf(" %"$sPRIfldbl" %"$sPRIfldbl" %"$sPRIfldbl"\n", nv, v, w);
91 return 0;
92}
93EOCP
57da76c4
JH
94 case "$osname:$gccversion" in
95 aix:) saveccflags="$ccflags"
96 ccflags="$ccflags -qlongdouble" ;; # to avoid core dump
97 esac
06bb3943
JH
98 set try
99 if eval $compile; then
0f00356b 100 foo=`$run ./try`
06bb3943
JH
101 case "$foo" in
102 *" 4294967303.150000 1.150000 4294967302.000000")
103 echo >&4 "Your modfl() is broken for large values."
73fce044 104 d_modfl_pow32_bug="$define"
06bb3943
JH
105 case "$foo" in
106 glibc) echo >&4 "You should upgrade your glibc to at least 2.2.2 to get a fixed modfl()."
107 ;;
108 esac
109 ;;
110 *" 4294967303.150000 0.150000 4294967303.000000")
111 echo >&4 "Your modfl() seems okay for large values."
112 ;;
113 *) echo >&4 "I don't understand your modfl() at all."
114 d_modfl="$undef"
115 ;;
116 esac
2cb64bf6 117 $rm_try
06bb3943
JH
118 else
119 echo "I cannot figure out whether your modfl() is okay, assuming it isn't."
120 d_modfl="$undef"
121 fi
57da76c4 122 case "$osname:$gccversion" in
aceb9765 123 aix:) ccflags="$saveccflags" ;; # restore
57da76c4 124 esac
06bb3943
JH
125 ;;
126esac
127
b21b2cb6 128if $test "$uselongdouble" = "$define"; then
1fbd636f
JH
129 message=""
130 if $test "$d_sqrtl" != "$define"; then
131 message="$message sqrtl"
132 fi
133 if $test "$d_modfl" != "$define"; then
7668538f
MBT
134 if $test "$d_truncl:$d_copysignl" = "$define:$define"; then
135 echo "You have both truncl and copysignl, so I can emulate modfl."
b21b2cb6 136 else
7668538f
MBT
137 if $test "$d_aintl:$d_copysignl" = "$define:$define"; then
138 echo "You have both aintl and copysignl, so I can emulate modfl."
139 else
140 message="$message modfl"
141 fi
b21b2cb6 142 fi
1fbd636f
JH
143 fi
144 if $test "$d_frexpl" != "$define"; then
145 if $test "$d_ilogbl:$d_scalbnl" = "$define:$define"; then
146 echo "You have both ilogbl and scalbnl, so I can emulate frexpl."
147 else
148 message="$message frexpl"
149 fi
150 fi
6cbd82a3
MBT
151 if $test "$d_ldexpl" != "$define"; then
152 message="$message ldexpl"
153 fi
b21b2cb6 154
1fbd636f 155 if $test "$message" != ""; then
b21b2cb6
JH
156 $cat <<EOM >&4
157
158*** You requested the use of long doubles but you do not seem to have
1fbd636f
JH
159*** the following mathematical functions needed for long double support:
160*** $message
4b62dc2e
JH
161*** Please rerun Configure without -Duselongdouble and/or -Dusemorebits.
162*** Cannot continue, aborting.
b21b2cb6
JH
163
164EOM
165
4b62dc2e 166 exit 1
b21b2cb6
JH
167 fi
168fi
169