xref: /netbsd-src/lib/libc/gdtoa/hdtoa.c (revision 30f557b6a1f15535a192ceb6fe00c32a9cea7b46)
1*30f557b6Sjakllsch /*	$NetBSD: hdtoa.c,v 1.14 2024/06/09 15:06:07 jakllsch Exp $	*/
2482b8dd6Schristos 
3482b8dd6Schristos /*-
4482b8dd6Schristos  * Copyright (c) 2004, 2005 David Schultz <das@FreeBSD.ORG>
5482b8dd6Schristos  * All rights reserved.
6482b8dd6Schristos  *
7482b8dd6Schristos  * Redistribution and use in source and binary forms, with or without
8482b8dd6Schristos  * modification, are permitted provided that the following conditions
9482b8dd6Schristos  * are met:
10482b8dd6Schristos  * 1. Redistributions of source code must retain the above copyright
11482b8dd6Schristos  *    notice, this list of conditions and the following disclaimer.
12482b8dd6Schristos  * 2. Redistributions in binary form must reproduce the above copyright
13482b8dd6Schristos  *    notice, this list of conditions and the following disclaimer in the
14482b8dd6Schristos  *    documentation and/or other materials provided with the distribution.
15482b8dd6Schristos  *
16482b8dd6Schristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17482b8dd6Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18482b8dd6Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19482b8dd6Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20482b8dd6Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21482b8dd6Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22482b8dd6Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23482b8dd6Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24482b8dd6Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25482b8dd6Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26482b8dd6Schristos  * SUCH DAMAGE.
27482b8dd6Schristos  */
28482b8dd6Schristos 
29482b8dd6Schristos #include <sys/cdefs.h>
30482b8dd6Schristos #if 0
31482b8dd6Schristos __FBSDID("$FreeBSD: src/lib/libc/gdtoa/_hdtoa.c,v 1.4 2007/01/03 04:57:58 das Exp $");
32482b8dd6Schristos #else
33*30f557b6Sjakllsch __RCSID("$NetBSD: hdtoa.c,v 1.14 2024/06/09 15:06:07 jakllsch Exp $");
34482b8dd6Schristos #endif
35482b8dd6Schristos 
36482b8dd6Schristos #include <float.h>
37482b8dd6Schristos #include <limits.h>
38482b8dd6Schristos #include <math.h>
39aa221fafSchristos #ifndef __vax__
40482b8dd6Schristos #include <machine/ieee.h>
4182708d0bSchristos #else
4282708d0bSchristos #include <machine/vaxfp.h>
4382708d0bSchristos #define ieee_double_u vax_dfloating_u
4482708d0bSchristos #define dblu_d dfltu_d
4582708d0bSchristos #define dblu_dbl dfltu_dflt
4682708d0bSchristos #define dbl_sign dflt_sign
4782708d0bSchristos #define dbl_exp dflt_exp
4882708d0bSchristos #define dbl_frach dflt_frach
4982708d0bSchristos #define dbl_fracm dflt_fracm
5082708d0bSchristos #define dbl_fracl dflt_fracl
5182708d0bSchristos #define DBL_FRACHBITS	DFLT_FRACHBITS
5282708d0bSchristos #define DBL_FRACMBITS	DFLT_FRACMBITS
5382708d0bSchristos #define DBL_FRACLBITS	DFLT_FRACLBITS
5482708d0bSchristos #define DBL_EXPBITS	DFLT_EXPBITS
55aa221fafSchristos #endif
56482b8dd6Schristos #include "gdtoaimp.h"
57482b8dd6Schristos 
58482b8dd6Schristos /* Strings values used by dtoa() */
59482b8dd6Schristos #define	INFSTR	"Infinity"
60482b8dd6Schristos #define	NANSTR	"NaN"
61482b8dd6Schristos 
62*30f557b6Sjakllsch #ifndef __vax__
63482b8dd6Schristos #define	DBL_ADJ		(DBL_MAX_EXP - 2 + ((DBL_MANT_DIG - 1) % 4))
64482b8dd6Schristos #define	LDBL_ADJ	(LDBL_MAX_EXP - 2 + ((LDBL_MANT_DIG - 1) % 4))
65*30f557b6Sjakllsch #else /* __vax__ */
66*30f557b6Sjakllsch #define	DBL_ADJ		(DBL_MAX_EXP + 4 + ((DBL_MANT_DIG) % 4))
67*30f557b6Sjakllsch #endif
68482b8dd6Schristos 
69482b8dd6Schristos /*
70482b8dd6Schristos  * Round up the given digit string.  If the digit string is fff...f,
71482b8dd6Schristos  * this procedure sets it to 100...0 and returns 1 to indicate that
72482b8dd6Schristos  * the exponent needs to be bumped.  Otherwise, 0 is returned.
73482b8dd6Schristos  */
74482b8dd6Schristos static int
roundup(char * s0,int ndigits)75482b8dd6Schristos roundup(char *s0, int ndigits)
76482b8dd6Schristos {
77482b8dd6Schristos 	char *s;
78482b8dd6Schristos 
79482b8dd6Schristos 	for (s = s0 + ndigits - 1; *s == 0xf; s--) {
80482b8dd6Schristos 		if (s == s0) {
81482b8dd6Schristos 			*s = 1;
82482b8dd6Schristos 			return (1);
83482b8dd6Schristos 		}
84482b8dd6Schristos 		*s = 0;
85482b8dd6Schristos 	}
86482b8dd6Schristos 	++*s;
87482b8dd6Schristos 	return (0);
88482b8dd6Schristos }
89482b8dd6Schristos 
90482b8dd6Schristos /*
91482b8dd6Schristos  * Round the given digit string to ndigits digits according to the
92482b8dd6Schristos  * current rounding mode.  Note that this could produce a string whose
93482b8dd6Schristos  * value is not representable in the corresponding floating-point
94482b8dd6Schristos  * type.  The exponent pointed to by decpt is adjusted if necessary.
95482b8dd6Schristos  */
96482b8dd6Schristos static void
dorounding(char * s0,int ndigits,int sign,int * decpt)97482b8dd6Schristos dorounding(char *s0, int ndigits, int sign, int *decpt)
98482b8dd6Schristos {
99482b8dd6Schristos 	int adjust = 0;	/* do we need to adjust the exponent? */
100482b8dd6Schristos 
101482b8dd6Schristos 	switch (FLT_ROUNDS) {
102482b8dd6Schristos 	case 0:		/* toward zero */
103482b8dd6Schristos 	default:	/* implementation-defined */
104482b8dd6Schristos 		break;
105482b8dd6Schristos 	case 1:		/* to nearest, halfway rounds to even */
106482b8dd6Schristos 		if ((s0[ndigits] > 8) ||
107482b8dd6Schristos 		    (s0[ndigits] == 8 && s0[ndigits - 1] & 1))
108482b8dd6Schristos 			adjust = roundup(s0, ndigits);
109482b8dd6Schristos 		break;
110482b8dd6Schristos 	case 2:		/* toward +inf */
111482b8dd6Schristos 		if (sign == 0)
112482b8dd6Schristos 			adjust = roundup(s0, ndigits);
113482b8dd6Schristos 		break;
114482b8dd6Schristos 	case 3:		/* toward -inf */
115482b8dd6Schristos 		if (sign != 0)
116482b8dd6Schristos 			adjust = roundup(s0, ndigits);
117482b8dd6Schristos 		break;
118482b8dd6Schristos 	}
119482b8dd6Schristos 
120482b8dd6Schristos 	if (adjust)
121482b8dd6Schristos 		*decpt += 4;
122482b8dd6Schristos }
123482b8dd6Schristos 
124482b8dd6Schristos /*
125482b8dd6Schristos  * This procedure converts a double-precision number in IEEE format
126482b8dd6Schristos  * into a string of hexadecimal digits and an exponent of 2.  Its
127482b8dd6Schristos  * behavior is bug-for-bug compatible with dtoa() in mode 2, with the
128482b8dd6Schristos  * following exceptions:
129482b8dd6Schristos  *
130482b8dd6Schristos  * - An ndigits < 0 causes it to use as many digits as necessary to
131482b8dd6Schristos  *   represent the number exactly.
132482b8dd6Schristos  * - The additional xdigs argument should point to either the string
133482b8dd6Schristos  *   "0123456789ABCDEF" or the string "0123456789abcdef", depending on
134482b8dd6Schristos  *   which case is desired.
135482b8dd6Schristos  * - This routine does not repeat dtoa's mistake of setting decpt
136482b8dd6Schristos  *   to 9999 in the case of an infinity or NaN.  INT_MAX is used
137482b8dd6Schristos  *   for this purpose instead.
138482b8dd6Schristos  *
139482b8dd6Schristos  * Note that the C99 standard does not specify what the leading digit
140482b8dd6Schristos  * should be for non-zero numbers.  For instance, 0x1.3p3 is the same
141482b8dd6Schristos  * as 0x2.6p2 is the same as 0x4.cp3.  This implementation chooses the
142482b8dd6Schristos  * first digit so that subsequent digits are aligned on nibble
143482b8dd6Schristos  * boundaries (before rounding).
144482b8dd6Schristos  *
145482b8dd6Schristos  * Inputs:	d, xdigs, ndigits
146482b8dd6Schristos  * Outputs:	decpt, sign, rve
147482b8dd6Schristos  */
148482b8dd6Schristos char *
hdtoa(double d,const char * xdigs,int ndigits,int * decpt,int * sign,char ** rve)149482b8dd6Schristos hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign,
150482b8dd6Schristos     char **rve)
151482b8dd6Schristos {
152482b8dd6Schristos 	static const int sigfigs = (DBL_MANT_DIG + 3) / 4;
153482b8dd6Schristos 	union ieee_double_u u;
154482b8dd6Schristos 	char *s, *s0;
155c8e7c687Schristos 	size_t bufsize;
156482b8dd6Schristos 
157482b8dd6Schristos 	u.dblu_d = d;
158482b8dd6Schristos 	*sign = u.dblu_dbl.dbl_sign;
159*30f557b6Sjakllsch #ifdef __vax__
160*30f557b6Sjakllsch 	u.dfltu_dflt.dflt_fracl =
161*30f557b6Sjakllsch 	    ((u.dfltu_dflt.dflt_fracl >> 16) & 0xFFFF) |
162*30f557b6Sjakllsch 	    ((u.dfltu_dflt.dflt_fracl & 0xffff) << 16);
163*30f557b6Sjakllsch #endif
164482b8dd6Schristos 
165482b8dd6Schristos 	switch (fpclassify(d)) {
166482b8dd6Schristos 	case FP_NORMAL:
167482b8dd6Schristos 		*decpt = u.dblu_dbl.dbl_exp - DBL_ADJ;
168482b8dd6Schristos 		break;
169482b8dd6Schristos 	case FP_ZERO:
170482b8dd6Schristos 		*decpt = 1;
171482b8dd6Schristos 		return (nrv_alloc("0", rve, 1));
172*30f557b6Sjakllsch #ifndef __vax__
173482b8dd6Schristos 	case FP_SUBNORMAL:
1742b13247bSchristos 		/* (DBL_MAX_EXP=1024 / 2) + 2 = 514? */
175482b8dd6Schristos 		u.dblu_d *= 0x1p514;
176482b8dd6Schristos 		*decpt = u.dblu_dbl.dbl_exp - (514 + DBL_ADJ);
177482b8dd6Schristos 		break;
178482b8dd6Schristos 	case FP_INFINITE:
179482b8dd6Schristos 		*decpt = INT_MAX;
180482b8dd6Schristos 		return (nrv_alloc(INFSTR, rve, sizeof(INFSTR) - 1));
181482b8dd6Schristos 	case FP_NAN:
182482b8dd6Schristos 		*decpt = INT_MAX;
183482b8dd6Schristos 		return (nrv_alloc(NANSTR, rve, sizeof(NANSTR) - 1));
184*30f557b6Sjakllsch #endif
185482b8dd6Schristos 	default:
186482b8dd6Schristos 		abort();
187482b8dd6Schristos 	}
188482b8dd6Schristos 
189482b8dd6Schristos 	/* FP_NORMAL or FP_SUBNORMAL */
190482b8dd6Schristos 
191482b8dd6Schristos 	if (ndigits == 0)		/* dtoa() compatibility */
192482b8dd6Schristos 		ndigits = 1;
193482b8dd6Schristos 
194482b8dd6Schristos 	/*
195482b8dd6Schristos 	 * For simplicity, we generate all the digits even if the
196482b8dd6Schristos 	 * caller has requested fewer.
197482b8dd6Schristos 	 */
198482b8dd6Schristos 	bufsize = (sigfigs > ndigits) ? sigfigs : ndigits;
199482b8dd6Schristos 	s0 = rv_alloc(bufsize);
200ab625449Schristos 	if (s0 == NULL)
201ab625449Schristos 		return NULL;
202482b8dd6Schristos 
203482b8dd6Schristos 	/*
204482b8dd6Schristos 	 * We work from right to left, first adding any requested zero
205482b8dd6Schristos 	 * padding, then the least significant portion of the
206482b8dd6Schristos 	 * mantissa, followed by the most significant.  The buffer is
207482b8dd6Schristos 	 * filled with the byte values 0x0 through 0xf, which are
208482b8dd6Schristos 	 * converted to xdigs[0x0] through xdigs[0xf] after the
209482b8dd6Schristos 	 * rounding phase.
210482b8dd6Schristos 	 */
211482b8dd6Schristos 	for (s = s0 + bufsize - 1; s > s0 + sigfigs - 1; s--)
212482b8dd6Schristos 		*s = 0;
213482b8dd6Schristos 	for (; s > s0 + sigfigs - (DBL_FRACLBITS / 4) - 1 && s > s0; s--) {
214482b8dd6Schristos 		*s = u.dblu_dbl.dbl_fracl & 0xf;
215482b8dd6Schristos 		u.dblu_dbl.dbl_fracl >>= 4;
216482b8dd6Schristos 	}
21782708d0bSchristos #ifdef DBL_FRACMBITS
218*30f557b6Sjakllsch 	for (; s > s0 + sigfigs - ((DBL_FRACLBITS + DBL_FRACMBITS) / 4) - 1
219*30f557b6Sjakllsch             && s > s0; s--) {
22082708d0bSchristos 		*s = u.dblu_dbl.dbl_fracm & 0xf;
22182708d0bSchristos 		u.dblu_dbl.dbl_fracm >>= 4;
22282708d0bSchristos 	}
22382708d0bSchristos #endif
224482b8dd6Schristos 	for (; s > s0; s--) {
225482b8dd6Schristos 		*s = u.dblu_dbl.dbl_frach & 0xf;
226482b8dd6Schristos 		u.dblu_dbl.dbl_frach >>= 4;
227482b8dd6Schristos 	}
228482b8dd6Schristos 
229482b8dd6Schristos 	/*
230482b8dd6Schristos 	 * At this point, we have snarfed all the bits in the
231482b8dd6Schristos 	 * mantissa, with the possible exception of the highest-order
232482b8dd6Schristos 	 * (partial) nibble, which is dealt with by the next
233482b8dd6Schristos 	 * statement.  We also tack on the implicit normalization bit.
234482b8dd6Schristos 	 */
235482b8dd6Schristos 	*s = u.dblu_dbl.dbl_frach | (1U << ((DBL_MANT_DIG - 1) % 4));
236482b8dd6Schristos 
237482b8dd6Schristos 	/* If ndigits < 0, we are expected to auto-size the precision. */
238482b8dd6Schristos 	if (ndigits < 0) {
239482b8dd6Schristos 		for (ndigits = sigfigs; s0[ndigits - 1] == 0; ndigits--)
240818764fcSchristos 			continue;
241482b8dd6Schristos 	}
242482b8dd6Schristos 
243482b8dd6Schristos 	if (sigfigs > ndigits && s0[ndigits] != 0)
244482b8dd6Schristos 		dorounding(s0, ndigits, u.dblu_dbl.dbl_sign, decpt);
245482b8dd6Schristos 
246482b8dd6Schristos 	s = s0 + ndigits;
247482b8dd6Schristos 	if (rve != NULL)
248482b8dd6Schristos 		*rve = s;
249482b8dd6Schristos 	*s-- = '\0';
250482b8dd6Schristos 	for (; s >= s0; s--)
251482b8dd6Schristos 		*s = xdigs[(unsigned int)*s];
252482b8dd6Schristos 
253482b8dd6Schristos 	return (s0);
254482b8dd6Schristos }
255482b8dd6Schristos 
256482b8dd6Schristos #if (LDBL_MANT_DIG > DBL_MANT_DIG)
257482b8dd6Schristos 
258482b8dd6Schristos /*
259482b8dd6Schristos  * This is the long double version of hdtoa().
260482b8dd6Schristos  */
261482b8dd6Schristos char *
hldtoa(long double e,const char * xdigs,int ndigits,int * decpt,int * sign,char ** rve)262482b8dd6Schristos hldtoa(long double e, const char *xdigs, int ndigits, int *decpt, int *sign,
263482b8dd6Schristos     char **rve)
264482b8dd6Schristos {
26512802f72Sriastradh 	static const int sigfigs = (LDBL_MANT_DIG + 3) / 4;
266482b8dd6Schristos 	union ieee_ext_u u;
267482b8dd6Schristos 	char *s, *s0;
268c8e7c687Schristos 	size_t bufsize;
269482b8dd6Schristos 
270bf90b280Smrg 	memset(&u, 0, sizeof u);
271482b8dd6Schristos 	u.extu_ld = e;
272482b8dd6Schristos 	*sign = u.extu_ext.ext_sign;
273482b8dd6Schristos 
274482b8dd6Schristos 	switch (fpclassify(e)) {
275482b8dd6Schristos 	case FP_NORMAL:
276482b8dd6Schristos 		*decpt = u.extu_ext.ext_exp - LDBL_ADJ;
277482b8dd6Schristos 		break;
278482b8dd6Schristos 	case FP_ZERO:
279482b8dd6Schristos 		*decpt = 1;
280482b8dd6Schristos 		return (nrv_alloc("0", rve, 1));
281482b8dd6Schristos 	case FP_SUBNORMAL:
282482b8dd6Schristos 		u.extu_ld *= 0x1p514L;
283482b8dd6Schristos 		*decpt = u.extu_ext.ext_exp - (514 + LDBL_ADJ);
284482b8dd6Schristos 		break;
285482b8dd6Schristos 	case FP_INFINITE:
286482b8dd6Schristos 		*decpt = INT_MAX;
287482b8dd6Schristos 		return (nrv_alloc(INFSTR, rve, sizeof(INFSTR) - 1));
288482b8dd6Schristos 	case FP_NAN:
289482b8dd6Schristos 		*decpt = INT_MAX;
290482b8dd6Schristos 		return (nrv_alloc(NANSTR, rve, sizeof(NANSTR) - 1));
291482b8dd6Schristos 	default:
292482b8dd6Schristos 		abort();
293482b8dd6Schristos 	}
294482b8dd6Schristos 
295482b8dd6Schristos 	/* FP_NORMAL or FP_SUBNORMAL */
296482b8dd6Schristos 
297482b8dd6Schristos 	if (ndigits == 0)		/* dtoa() compatibility */
298482b8dd6Schristos 		ndigits = 1;
299482b8dd6Schristos 
300482b8dd6Schristos 	/*
301482b8dd6Schristos 	 * For simplicity, we generate all the digits even if the
302482b8dd6Schristos 	 * caller has requested fewer.
303482b8dd6Schristos 	 */
304482b8dd6Schristos 	bufsize = (sigfigs > ndigits) ? sigfigs : ndigits;
305482b8dd6Schristos 	s0 = rv_alloc(bufsize);
306ab625449Schristos 	if (s0 == NULL)
307ab625449Schristos 		return NULL;
308482b8dd6Schristos 
309482b8dd6Schristos 	/*
310482b8dd6Schristos 	 * We work from right to left, first adding any requested zero
311482b8dd6Schristos 	 * padding, then the least significant portion of the
312482b8dd6Schristos 	 * mantissa, followed by the most significant.  The buffer is
313482b8dd6Schristos 	 * filled with the byte values 0x0 through 0xf, which are
314482b8dd6Schristos 	 * converted to xdigs[0x0] through xdigs[0xf] after the
315482b8dd6Schristos 	 * rounding phase.
316482b8dd6Schristos 	 */
317482b8dd6Schristos 	for (s = s0 + bufsize - 1; s > s0 + sigfigs - 1; s--)
318482b8dd6Schristos 		*s = 0;
31912802f72Sriastradh 	for (; s > s0 + sigfigs - (EXT_FRACLBITS / 4) - 1 && s > s0; s--) {
320482b8dd6Schristos 		*s = u.extu_ext.ext_fracl & 0xf;
321482b8dd6Schristos 		u.extu_ext.ext_fracl >>= 4;
322482b8dd6Schristos 	}
323818764fcSchristos #ifdef EXT_FRACHMBITS
32412802f72Sriastradh 	for (; s > s0; s--) {
325818764fcSchristos 		*s = u.extu_ext.ext_frachm & 0xf;
326818764fcSchristos 		u.extu_ext.ext_frachm >>= 4;
327818764fcSchristos 	}
328818764fcSchristos #endif
329818764fcSchristos #ifdef EXT_FRACLMBITS
33012802f72Sriastradh 	for (; s > s0; s--) {
331818764fcSchristos 		*s = u.extu_ext.ext_fraclm & 0xf;
332818764fcSchristos 		u.extu_ext.ext_fraclm >>= 4;
333818764fcSchristos 	}
334818764fcSchristos #endif
33512802f72Sriastradh 	for (; s > s0; s--) {
336482b8dd6Schristos 		*s = u.extu_ext.ext_frach & 0xf;
337482b8dd6Schristos 		u.extu_ext.ext_frach >>= 4;
338482b8dd6Schristos 	}
339482b8dd6Schristos 
340482b8dd6Schristos 	/*
341482b8dd6Schristos 	 * At this point, we have snarfed all the bits in the
342482b8dd6Schristos 	 * mantissa, with the possible exception of the highest-order
343482b8dd6Schristos 	 * (partial) nibble, which is dealt with by the next
344482b8dd6Schristos 	 * statement.  We also tack on the implicit normalization bit.
345482b8dd6Schristos 	 */
34612802f72Sriastradh 	*s = u.extu_ext.ext_frach | (1U << ((LDBL_MANT_DIG - 1) % 4));
347482b8dd6Schristos 
348482b8dd6Schristos 	/* If ndigits < 0, we are expected to auto-size the precision. */
349482b8dd6Schristos 	if (ndigits < 0) {
350482b8dd6Schristos 		for (ndigits = sigfigs; s0[ndigits - 1] == 0; ndigits--)
351482b8dd6Schristos 			continue;
352482b8dd6Schristos 	}
353482b8dd6Schristos 
354482b8dd6Schristos 	if (sigfigs > ndigits && s0[ndigits] != 0)
355482b8dd6Schristos 		dorounding(s0, ndigits, u.extu_ext.ext_sign, decpt);
356482b8dd6Schristos 
357482b8dd6Schristos 	s = s0 + ndigits;
358482b8dd6Schristos 	if (rve != NULL)
359482b8dd6Schristos 		*rve = s;
360482b8dd6Schristos 	*s-- = '\0';
361482b8dd6Schristos 	for (; s >= s0; s--)
362482b8dd6Schristos 		*s = xdigs[(unsigned int)*s];
363482b8dd6Schristos 
364482b8dd6Schristos 	return (s0);
365482b8dd6Schristos }
366482b8dd6Schristos 
367482b8dd6Schristos #else	/* (LDBL_MANT_DIG == DBL_MANT_DIG) */
368482b8dd6Schristos 
369482b8dd6Schristos char *
hldtoa(long double e,const char * xdigs,int ndigits,int * decpt,int * sign,char ** rve)370482b8dd6Schristos hldtoa(long double e, const char *xdigs, int ndigits, int *decpt, int *sign,
371482b8dd6Schristos     char **rve)
372482b8dd6Schristos {
373482b8dd6Schristos 
374482b8dd6Schristos 	return (hdtoa((double)e, xdigs, ndigits, decpt, sign, rve));
375482b8dd6Schristos }
376482b8dd6Schristos 
377482b8dd6Schristos #endif	/* (LDBL_MANT_DIG == DBL_MANT_DIG) */
378