xref: /titanic_41/usr/src/lib/libc/sparc/gen/ecvt.c (revision 6185db853e024a486ff8837e6784dd290d866112)
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 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*	Copyright (c) 1988 AT&T	*/
30 /*	  All Rights Reserved  	*/
31 
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 #pragma weak ecvt = _ecvt
41 #pragma weak fcvt = _fcvt
42 #pragma weak qecvt = _qecvt
43 #pragma weak qfcvt = _qfcvt
44 #pragma weak qgcvt = _qgcvt
45 
46 #include "synonyms.h"
47 #include <sys/types.h>
48 #include <stdlib.h>
49 #include <floatingpoint.h>
50 #include "tsd.h"
51 
52 char *
53 ecvt(double number, int ndigits, int *decpt, int *sign)
54 {
55 	char *buf = tsdalloc(_T_ECVT, DECIMAL_STRING_LENGTH, NULL);
56 
57 	return (econvert(number, ndigits, decpt, sign, buf));
58 }
59 
60 char *
61 fcvt(double number, int ndigits, int *decpt, int *sign)
62 {
63 	char *buf = tsdalloc(_T_ECVT, DECIMAL_STRING_LENGTH, NULL);
64 	char *ptr, *val;
65 	char ch;
66 	int deci_val;
67 
68 	ptr = fconvert(number, ndigits, decpt, sign, buf);
69 
70 	val = ptr;
71 	deci_val = *decpt;
72 
73 	while ((ch = *ptr) != 0) {
74 		if (ch != '0') { /* You execute this if there are no */
75 				    /* leading zero's remaining. */
76 			*decpt = deci_val; /* If there are leading zero's */
77 			return (ptr);		/* gets updated. */
78 		}
79 		ptr++;
80 		deci_val--;
81 	}
82 	return (val);
83 }
84 
85 char *
86 qecvt(
87 	long double	number,
88 	int		ndigits,
89 	int		*decpt,
90 	int		*sign)
91 {
92 	char *buf = tsdalloc(_T_ECVT, DECIMAL_STRING_LENGTH, NULL);
93 
94 	return (qeconvert(&number, ndigits, decpt, sign, buf));
95 }
96 
97 char *
98 qfcvt(long double number, int ndigits, int *decpt, int *sign)
99 {
100 	char *buf = tsdalloc(_T_ECVT, DECIMAL_STRING_LENGTH, NULL);
101 
102 	return (qfconvert(&number, ndigits, decpt, sign, buf));
103 }
104 
105 char *
106 qgcvt(long double number, int ndigits, char *buffer)
107 {
108 	return (qgconvert(&number, ndigits, 0, buffer));
109 }
110