1 ?RCS: $Id: d_gconvert.U,v 3.0.1.3 1997/02/28 15:33:38 ram Exp $
3 ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
5 ?RCS: You may redistribute only under the terms of the Artistic Licence,
6 ?RCS: as specified in the README file that comes with the distribution.
7 ?RCS: You may reuse parts of this distribution only within the terms of
8 ?RCS: that same Artistic Licence; a copy of which may be found at the root
9 ?RCS: of the source tree for dist 3.0.
11 ?RCS: Original Author: Andy Dougherty <doughera@lafcol.lafayette.edu>
13 ?RCS: $Log: d_gconvert.U,v $
14 ?RCS: Revision 3.0.1.3 1997/02/28 15:33:38 ram
15 ?RCS: patch61: integrated new unit from perl5
17 ?RCS: Revision 3.0.1.2 1995/07/25 13:55:59 ram
18 ?RCS: patch56: improved comments about the Gconvert macro (ADO)
19 ?RCS: patch56: force compile-link test since it may exist but be unusable (ADO)
21 ?RCS: Revision 3.0.1.1 1994/10/29 16:12:51 ram
22 ?RCS: patch36: created by ADO
24 ?MAKE:d_Gconvert: Compile cat Inlibc rm _o
25 ?MAKE: -pick add $@ %<
27 ?S: This variable holds what Gconvert is defined as to convert
28 ?S: floating point numbers into strings. It could be 'gconvert'
29 ?S: or a more complex macro emulating gconvert with gcvt() or sprintf.
30 ?S: Possible values are:
31 ?S: d_Gconvert='gconvert((x),(n),(t),(b))'
32 ?S: d_Gconvert='gcvt((x),(n),(b))'
33 ?S: d_Gconvert='sprintf((b),"%.*g",(n),(x))'
36 ?C: This preprocessor macro is defined to convert a floating point
37 ?C: number to a string without a trailing decimal point. This
38 ?C: emulates the behavior of sprintf("%g"), but is sometimes much more
39 ?C: efficient. If gconvert() is not available, but gcvt() drops the
40 ?C: trailing decimal point, then gcvt() is used. If all else fails,
41 ?C: a macro using sprintf("%g") is used. Arguments for the Gconvert
42 ?C: macro are: value, number of digits, whether trailing zeros should
43 ?C: be retained, and the output buffer.
44 ?C: Possible values are:
45 ?C: d_Gconvert='gconvert((x),(n),(t),(b))'
46 ?C: d_Gconvert='gcvt((x),(n),(b))'
47 ?C: d_Gconvert='sprintf((b),"%.*g",(n),(x))'
48 ?C: The last two assume trailing zeros should not be kept.
50 ?H:#define Gconvert(x,n,t,b) $d_Gconvert
52 ?T: xxx_list xxx_convert
55 : Check how to convert floats to strings.
56 if test "X$d_Gconvert" = X; then
58 echo "Checking for an efficient way to convert floats to strings."
61 #define Gconvert(x,n,t,b) gconvert((x),(n),(t),(b))
62 char *myname = "gconvert";
65 #define Gconvert(x,n,t,b) gcvt((x),(n),(b))
66 char *myname = "gcvt";
69 #define Gconvert(x,n,t,b) sprintf((b),"%.*g",(n),(x))
70 char *myname = "sprintf";
80 if (strcmp(expect, got)) {
81 printf("%s oddity: Expected %s, got %s\n",
92 /* This must be 1st test on (which?) platform */
93 /* Alan Burlison <AlanBurlsin@unn.unisys.com> */
94 Gconvert(0.1, 8, 0, buf);
97 Gconvert(1.0, 8, 0, buf);
100 Gconvert(0.0, 8, 0, buf);
103 Gconvert(-1.0, 8, 0, buf);
106 /* Some Linux gcvt's give 1.e+5 here. */
107 Gconvert(100000.0, 8, 0, buf);
108 checkit("100000", buf);
110 /* Some Linux gcvt's give -1.e+5 here. */
111 Gconvert(-100000.0, 8, 0, buf);
112 checkit("-100000", buf);
117 ?X: List of order in which to search for functions.
118 ?X: Usual order of efficiency is gconvert gcvt sprintf
119 ?X: If a hint file sets a d_Gconvert="gconvert" or "gcvt" or "sprintf",
120 ?X: then that is taken as a hint for which function to try first.
121 ?X: (e.g. that function may be in a problematic /usr/ucblib library, and
122 ?X: the user may or may not choose to use -lucb stuff.)
123 ?X: Any other hint file (or previous config.sh) setting is left intact.
124 case "$d_Gconvert" in
125 gconvert*) xxx_list='gconvert gcvt sprintf' ;;
126 gcvt*) xxx_list='gcvt gconvert sprintf' ;;
127 sprintf*) xxx_list='sprintf gconvert gcvt' ;;
128 *) xxx_list='gconvert gcvt sprintf' ;;
131 for xxx_convert in $xxx_list; do
132 echo "Trying $xxx_convert"
134 set try -DTRY_$xxx_convert
135 if eval $compile; then
136 echo "$xxx_convert" found. >&4
138 echo "I'll use $xxx_convert to convert floats into a string." >&4
141 echo "...But $xxx_convert didn't work as I expected."
144 echo "$xxx_convert NOT found." >&4
148 case "$xxx_convert" in
149 gconvert) d_Gconvert='gconvert((x),(n),(t),(b))' ;;
150 gcvt) d_Gconvert='gcvt((x),(n),(b))' ;;
151 *) d_Gconvert='sprintf((b),"%.*g",(n),(x))' ;;