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.
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.
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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 #include "base_conversion.h"
32 #include <sys/types.h>
36 * Copies the appropriate string for a datum of class cl into *buf,
37 * choosing "Inf" or "Infinity" according to ndigits, the desired
38 * output string length.
41 __infnanstring(enum fp_class_type cl
, int ndigits
, char *buf
)
43 if (cl
== fp_infinity
) {
45 (void) memcpy(buf
, "Inf", 4);
47 (void) memcpy(buf
, "Infinity", 9);
50 (void) memcpy(buf
, "NaN", 4);
56 econvert(double arg
, int ndigits
, int *decpt
, int *sign
, char *buf
)
60 fp_exception_field_type ef
;
65 #elif defined(__i386) || defined(__amd64)
68 #error Unknown architecture
70 dm
.df
= floating_form
; /* E format. */
73 else if (ndigits
>= DECIMAL_STRING_LENGTH
)
74 ndigits
= DECIMAL_STRING_LENGTH
- 1;
75 dm
.ndigits
= ndigits
; /* Number of significant digits. */
76 double_to_decimal(&arg
, &dm
, &dr
, &ef
);
81 *decpt
= dr
.exponent
+ ndigits
;
82 for (i
= 0; i
< ndigits
; i
++)
88 for (i
= 0; i
< ndigits
; i
++)
94 __infnanstring(dr
.fpclass
, ndigits
, buf
);
101 seconvert(single
*arg
, int ndigits
, int *decpt
, int *sign
, char *buf
)
105 fp_exception_field_type ef
;
110 #elif defined(__i386) || defined(__amd64)
113 #error Unknown architecture
115 dm
.df
= floating_form
; /* E format. */
118 else if (ndigits
>= DECIMAL_STRING_LENGTH
)
119 ndigits
= DECIMAL_STRING_LENGTH
- 1;
120 dm
.ndigits
= ndigits
; /* Number of significant digits. */
121 single_to_decimal(arg
, &dm
, &dr
, &ef
);
123 switch (dr
.fpclass
) {
126 *decpt
= dr
.exponent
+ ndigits
;
127 for (i
= 0; i
< ndigits
; i
++)
133 for (i
= 0; i
< ndigits
; i
++)
139 __infnanstring(dr
.fpclass
, ndigits
, buf
);
146 qeconvert(quadruple
*arg
, int ndigits
, int *decpt
, int *sign
, char *buf
)
150 fp_exception_field_type ef
;
155 #elif defined(__i386) || defined(__amd64)
158 #error Unknown architecture
160 dm
.df
= floating_form
; /* E format. */
163 else if (ndigits
>= DECIMAL_STRING_LENGTH
)
164 ndigits
= DECIMAL_STRING_LENGTH
- 1;
165 dm
.ndigits
= ndigits
; /* Number of significant digits. */
167 quadruple_to_decimal(arg
, &dm
, &dr
, &ef
);
168 #elif defined(__i386) || defined(__amd64)
169 extended_to_decimal((extended
*)arg
, &dm
, &dr
, &ef
);
171 #error Unknown architecture
174 switch (dr
.fpclass
) {
177 *decpt
= dr
.exponent
+ ndigits
;
178 for (i
= 0; i
< ndigits
; i
++)
184 for (i
= 0; i
< ndigits
; i
++)
190 __infnanstring(dr
.fpclass
, ndigits
, buf
);