xref: /titanic_52/usr/src/lib/libc/amd64/gen/ecvt.c (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1988 AT&T	*/
23 /*	  All Rights Reserved	*/
24 
25 
26 /*
27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 /*
34  *	ecvt converts to decimal
35  *	the number of digits is specified by ndigit
36  *	decpt is set to the position of the decimal point
37  *	sign is set to 0 for positive, 1 for negative
38  *
39  */
40 
41 #pragma weak ecvt = _ecvt
42 #pragma weak fcvt = _fcvt
43 #pragma weak qecvt = _qecvt
44 #pragma weak qfcvt = _qfcvt
45 #pragma weak qgcvt = _qgcvt
46 
47 #include "synonyms.h"
48 #include <sys/types.h>
49 #include <stdlib.h>
50 #include <floatingpoint.h>
51 #include "tsd.h"
52 
53 char *
54 ecvt(number, ndigits, decpt, sign)
55 	double	number;
56 	int	ndigits;
57 	int	*decpt;
58 	int	*sign;
59 {
60 	char *buf = tsdalloc(_T_ECVT, DECIMAL_STRING_LENGTH, NULL);
61 
62 	return (econvert(number, ndigits, decpt, sign, buf));
63 }
64 
65 char *
66 fcvt(number, ndigits, decpt, sign)
67 	double	number;
68 	int	ndigits;
69 	int	*decpt;
70 	int	*sign;
71 {
72 	char *buf = tsdalloc(_T_ECVT, DECIMAL_STRING_LENGTH, NULL);
73 	char *ptr, *val;
74 	char ch;
75 	int deci_val;
76 
77 	ptr = fconvert(number, ndigits, decpt, sign, buf);
78 	val = ptr;
79 	deci_val = *decpt;
80 
81 	while ((ch = *ptr) != '\0') {
82 		if (ch != '0') { /* You execute this if there are no */
83 				/* leading zero's remaining. */
84 			*decpt = deci_val; /* If there are leading zero's */
85 			return (ptr);	/* gets updated. */
86 		}
87 		ptr++;
88 		deci_val--;
89 	}
90 	return (val);
91 }
92 
93 char *
94 qecvt(number, ndigits, decpt, sign)
95 	long double	number;
96 	int		ndigits;
97 	int		*decpt;
98 	int		*sign;
99 {
100 	char *buf = tsdalloc(_T_ECVT, DECIMAL_STRING_LENGTH, NULL);
101 
102 	return (qeconvert(&number, ndigits, decpt, sign, buf));
103 }
104 
105 char *
106 qfcvt(number, ndigits, decpt, sign)
107 	long double	number;
108 	int		ndigits;
109 	int		*decpt;
110 	int		*sign;
111 {
112 	char *buf = tsdalloc(_T_ECVT, DECIMAL_STRING_LENGTH, NULL);
113 
114 	return (qfconvert(&number, ndigits, decpt, sign, buf));
115 }
116 
117 char *
118 qgcvt(number, ndigits, buffer)
119 	long double	number;
120 	int		ndigits;
121 	char		*buffer;
122 {
123 	return (qgconvert(&number, ndigits, 0, buffer));
124 }
125