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