xref: /onnv-gate/usr/src/lib/libbc/libc/gen/common/float_decim.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
23*0Sstevel@tonic-gate 
24*0Sstevel@tonic-gate /*
25*0Sstevel@tonic-gate  * Copyright (c) 1988 by Sun Microsystems, Inc.
26*0Sstevel@tonic-gate  */
27*0Sstevel@tonic-gate 
28*0Sstevel@tonic-gate /*
29*0Sstevel@tonic-gate  * Conversion between single, and extended binary and decimal
30*0Sstevel@tonic-gate  * floating point - separated from double_to_decimal to minimize impact on
31*0Sstevel@tonic-gate  * main(){printf("Hello");}
32*0Sstevel@tonic-gate  */
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #include "base_conversion.h"
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate void
single_to_decimal(px,pm,pd,ps)37*0Sstevel@tonic-gate single_to_decimal(px, pm, pd, ps)
38*0Sstevel@tonic-gate 	single         *px;
39*0Sstevel@tonic-gate 	decimal_mode   *pm;
40*0Sstevel@tonic-gate 	decimal_record *pd;
41*0Sstevel@tonic-gate 	fp_exception_field_type *ps;
42*0Sstevel@tonic-gate {
43*0Sstevel@tonic-gate 	single_equivalence kluge;
44*0Sstevel@tonic-gate 	unpacked        u;
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate 	*ps = 0;		/* Initialize *ps - no exceptions. */
47*0Sstevel@tonic-gate 	kluge.x = *px;
48*0Sstevel@tonic-gate 	pd->sign = kluge.f.msw.sign;
49*0Sstevel@tonic-gate 	pd->fpclass = _class_single(px);
50*0Sstevel@tonic-gate 	switch (pd->fpclass) {
51*0Sstevel@tonic-gate 	case fp_zero:
52*0Sstevel@tonic-gate 		break;
53*0Sstevel@tonic-gate 	case fp_infinity:
54*0Sstevel@tonic-gate 		break;
55*0Sstevel@tonic-gate 	case fp_quiet:
56*0Sstevel@tonic-gate 		break;
57*0Sstevel@tonic-gate 	case fp_signaling:
58*0Sstevel@tonic-gate 		break;
59*0Sstevel@tonic-gate 	default:
60*0Sstevel@tonic-gate 		_unpack_single(&u, &kluge.x);
61*0Sstevel@tonic-gate 		_unpacked_to_decimal(&u, pm, pd, ps);
62*0Sstevel@tonic-gate 	}
63*0Sstevel@tonic-gate }
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate void
extended_to_decimal(px,pm,pd,ps)66*0Sstevel@tonic-gate extended_to_decimal(px, pm, pd, ps)
67*0Sstevel@tonic-gate 	extended       *px;
68*0Sstevel@tonic-gate 	decimal_mode   *pm;
69*0Sstevel@tonic-gate 	decimal_record *pd;
70*0Sstevel@tonic-gate 	fp_exception_field_type *ps;
71*0Sstevel@tonic-gate {
72*0Sstevel@tonic-gate 	extended_equivalence kluge;
73*0Sstevel@tonic-gate 	unpacked        u;
74*0Sstevel@tonic-gate 
75*0Sstevel@tonic-gate 	*ps = 0;		/* Initialize *ps - no exceptions. */
76*0Sstevel@tonic-gate 	kluge.x[0] = (*px)[0];
77*0Sstevel@tonic-gate 	kluge.x[1] = (*px)[1];
78*0Sstevel@tonic-gate 	kluge.x[2] = (*px)[2];
79*0Sstevel@tonic-gate 	pd->sign = kluge.f.msw.sign;
80*0Sstevel@tonic-gate 	pd->fpclass = _class_extended(px);
81*0Sstevel@tonic-gate 	switch (pd->fpclass) {
82*0Sstevel@tonic-gate 	case fp_zero:
83*0Sstevel@tonic-gate 		break;
84*0Sstevel@tonic-gate 	case fp_infinity:
85*0Sstevel@tonic-gate 		break;
86*0Sstevel@tonic-gate 	case fp_quiet:
87*0Sstevel@tonic-gate 		break;
88*0Sstevel@tonic-gate 	case fp_signaling:
89*0Sstevel@tonic-gate 		break;
90*0Sstevel@tonic-gate 	default:
91*0Sstevel@tonic-gate 		_unpack_extended(&u, px);
92*0Sstevel@tonic-gate 		_unpacked_to_decimal(&u, pm, pd, ps);
93*0Sstevel@tonic-gate 	}
94*0Sstevel@tonic-gate }
95