xref: /titanic_44/usr/src/lib/libbc/inc/include/floatingpoint.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
23*7c478bd9Sstevel@tonic-gate 
24*7c478bd9Sstevel@tonic-gate /*
25*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1988 by Sun Microsystems, Inc.
26*7c478bd9Sstevel@tonic-gate  */
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate /*
29*7c478bd9Sstevel@tonic-gate  * IEEE floating-point definitions for constants, types, variables, and
30*7c478bd9Sstevel@tonic-gate  * functions implemented in libc.a for: IEEE floating-point arithmetic base
31*7c478bd9Sstevel@tonic-gate  * conversion; IEEE floating-point arithmetic modes; IEEE floating-point
32*7c478bd9Sstevel@tonic-gate  * arithmetic exception handling; certain functions defined in 4.3 BSD and
33*7c478bd9Sstevel@tonic-gate  * System V.
34*7c478bd9Sstevel@tonic-gate  */
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #ifndef _floatingpoint_h
37*7c478bd9Sstevel@tonic-gate #define _floatingpoint_h
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate #include <sys/ieeefp.h>
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate /* Sun TYPES for IEEE floating point.	 */
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate typedef float   single;
44*7c478bd9Sstevel@tonic-gate typedef unsigned long extended[3];	/* MC68881/i80387 double-extended type. */
45*7c478bd9Sstevel@tonic-gate #ifdef __STDC__
46*7c478bd9Sstevel@tonic-gate typedef long double quadruple;	/* Quadruple-precision type. */
47*7c478bd9Sstevel@tonic-gate #else
48*7c478bd9Sstevel@tonic-gate typedef struct {
49*7c478bd9Sstevel@tonic-gate 	unsigned long   u[4];
50*7c478bd9Sstevel@tonic-gate }               quadruple;	/* Quadruple-precision type. */
51*7c478bd9Sstevel@tonic-gate #endif
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate #define N_IEEE_EXCEPTION 5	/* Number of floating-point exceptions. */
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate typedef unsigned fp_exception_field_type;
56*7c478bd9Sstevel@tonic-gate /*
57*7c478bd9Sstevel@tonic-gate  * A field containing fp_exceptions OR'ed together.
58*7c478bd9Sstevel@tonic-gate  */
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate typedef int     sigfpe_code_type;	/* Type of SIGFPE code. */
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate typedef void    (*sigfpe_handler_type) ();
63*7c478bd9Sstevel@tonic-gate /* Pointer to exception handler function. */
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate #define SIGFPE_DEFAULT	(void (*)())0	/* default exception handling */
66*7c478bd9Sstevel@tonic-gate #define SIGFPE_IGNORE	(void (*)())1	/* ignore this exception or code */
67*7c478bd9Sstevel@tonic-gate #define SIGFPE_ABORT	(void (*)())2	/* force abort on exception */
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate /* Sun VARIABLES for IEEE floating point. */
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate extern enum fp_direction_type fp_direction;
72*7c478bd9Sstevel@tonic-gate /*
73*7c478bd9Sstevel@tonic-gate  * Current rounding direction. Updated by ieee_flags.
74*7c478bd9Sstevel@tonic-gate  */
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate extern enum fp_precision_type fp_precision;
77*7c478bd9Sstevel@tonic-gate /*
78*7c478bd9Sstevel@tonic-gate  * Current rounding precision. Updated by ieee_flags.
79*7c478bd9Sstevel@tonic-gate  */
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate extern fp_exception_field_type fp_accrued_exceptions;
82*7c478bd9Sstevel@tonic-gate /*
83*7c478bd9Sstevel@tonic-gate  * Sticky accumulated exceptions, updated by ieee_flags. In hardware
84*7c478bd9Sstevel@tonic-gate  * implementations this variable is not automatically updated as the hardware
85*7c478bd9Sstevel@tonic-gate  * changes and should therefore not be relied on directly.
86*7c478bd9Sstevel@tonic-gate  */
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate /* Sun definitions for base conversion.			 */
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate #define DECIMAL_STRING_LENGTH 512
91*7c478bd9Sstevel@tonic-gate /* Size of buffer in decimal_record. */
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate typedef char    decimal_string[DECIMAL_STRING_LENGTH];
94*7c478bd9Sstevel@tonic-gate /* Decimal significand. */
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate typedef struct {
97*7c478bd9Sstevel@tonic-gate 	enum fp_class_type fpclass;
98*7c478bd9Sstevel@tonic-gate 	int             sign;
99*7c478bd9Sstevel@tonic-gate 	int             exponent;
100*7c478bd9Sstevel@tonic-gate 	decimal_string  ds;	/* Significand - each char contains an ascii
101*7c478bd9Sstevel@tonic-gate 				 * digit, except the string-terminating ascii
102*7c478bd9Sstevel@tonic-gate 				 * null. */
103*7c478bd9Sstevel@tonic-gate 	int             more;	/* On conversion from decimal to binary, != 0
104*7c478bd9Sstevel@tonic-gate 				 * indicates more non-zero digits following
105*7c478bd9Sstevel@tonic-gate 				 * ds. */
106*7c478bd9Sstevel@tonic-gate 	int             ndigits;/* On fixed_form conversion from binary to
107*7c478bd9Sstevel@tonic-gate 				 * decimal, contains number of digits
108*7c478bd9Sstevel@tonic-gate 				 * required for ds. */
109*7c478bd9Sstevel@tonic-gate }
110*7c478bd9Sstevel@tonic-gate                 decimal_record;
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate enum decimal_form {
113*7c478bd9Sstevel@tonic-gate 	fixed_form,		/* Fortran F format: ndigits specifies number
114*7c478bd9Sstevel@tonic-gate 				 * of digits after point; if negative,
115*7c478bd9Sstevel@tonic-gate 				 * specifies rounding to occur to left of
116*7c478bd9Sstevel@tonic-gate 				 * point. */
117*7c478bd9Sstevel@tonic-gate 	floating_form		/* Fortran E format: ndigits specifies number
118*7c478bd9Sstevel@tonic-gate 				 * of significant digits. */
119*7c478bd9Sstevel@tonic-gate };
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate typedef struct {
122*7c478bd9Sstevel@tonic-gate 	enum fp_direction_type rd;
123*7c478bd9Sstevel@tonic-gate 	/* Rounding direction. */
124*7c478bd9Sstevel@tonic-gate 	enum decimal_form df;	/* Format for binary to decimal conversion. */
125*7c478bd9Sstevel@tonic-gate 	int             ndigits;/* Number of digits for conversion. */
126*7c478bd9Sstevel@tonic-gate }
127*7c478bd9Sstevel@tonic-gate                 decimal_mode;
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate enum decimal_string_form {	/* Valid decimal number string formats. */
130*7c478bd9Sstevel@tonic-gate 	invalid_form,		/* Not a valid decimal string format. */
131*7c478bd9Sstevel@tonic-gate 	whitespace_form,	/* All white space - valid in Fortran! */
132*7c478bd9Sstevel@tonic-gate 	fixed_int_form,		/* <digs> 		 */
133*7c478bd9Sstevel@tonic-gate 	fixed_intdot_form,	/* <digs>. 		 */
134*7c478bd9Sstevel@tonic-gate 	fixed_dotfrac_form,	/* .<digs>		 */
135*7c478bd9Sstevel@tonic-gate 	fixed_intdotfrac_form,	/* <digs>.<frac>	 */
136*7c478bd9Sstevel@tonic-gate 	floating_int_form,	/* <digs><exp>		 */
137*7c478bd9Sstevel@tonic-gate 	floating_intdot_form,	/* <digs>.<exp>		 */
138*7c478bd9Sstevel@tonic-gate 	floating_dotfrac_form,	/* .<digs><exp>		 */
139*7c478bd9Sstevel@tonic-gate 	floating_intdotfrac_form,	/* <digs>.<digs><exp>	 */
140*7c478bd9Sstevel@tonic-gate 	inf_form,		/* inf			 */
141*7c478bd9Sstevel@tonic-gate 	infinity_form,		/* infinity		 */
142*7c478bd9Sstevel@tonic-gate 	nan_form,		/* nan			 */
143*7c478bd9Sstevel@tonic-gate 	nanstring_form		/* nan(string)		 */
144*7c478bd9Sstevel@tonic-gate };
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate /*	The following externs are used in the implementation of sprintf.		*/
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate extern void     double_to_decimal();
149*7c478bd9Sstevel@tonic-gate extern void     quadruple_to_decimal();
150*7c478bd9Sstevel@tonic-gate extern char    *econvert();
151*7c478bd9Sstevel@tonic-gate extern char    *fconvert();
152*7c478bd9Sstevel@tonic-gate extern char    *gconvert();
153*7c478bd9Sstevel@tonic-gate extern char    *qeconvert();
154*7c478bd9Sstevel@tonic-gate extern char    *qfconvert();
155*7c478bd9Sstevel@tonic-gate extern char    *qgconvert();
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate /*
158*7c478bd9Sstevel@tonic-gate 	The following are used for other parts of base conversion.
159*7c478bd9Sstevel@tonic-gate */
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate extern sigfpe_handler_type ieee_handlers[N_IEEE_EXCEPTION];
162*7c478bd9Sstevel@tonic-gate /*
163*7c478bd9Sstevel@tonic-gate  * Array of pointers to functions to handle SIGFPE's corresponding to IEEE
164*7c478bd9Sstevel@tonic-gate  * fp_exceptions. sigfpe_default means do not generate SIGFPE. An invalid
165*7c478bd9Sstevel@tonic-gate  * address such as sigfpe_abort will cause abort on that SIGFPE. Updated by
166*7c478bd9Sstevel@tonic-gate  * ieee_handler.
167*7c478bd9Sstevel@tonic-gate  */
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate extern sigfpe_handler_type sigfpe();
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate extern void     single_to_decimal();
172*7c478bd9Sstevel@tonic-gate extern void     extended_to_decimal();
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate extern void     decimal_to_single();
175*7c478bd9Sstevel@tonic-gate extern void     decimal_to_double();
176*7c478bd9Sstevel@tonic-gate extern void     decimal_to_extended();
177*7c478bd9Sstevel@tonic-gate extern void     decimal_to_quadruple();
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate extern char    *seconvert();
180*7c478bd9Sstevel@tonic-gate extern char    *sfconvert();
181*7c478bd9Sstevel@tonic-gate extern char    *sgconvert();
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate extern void     string_to_decimal();
184*7c478bd9Sstevel@tonic-gate extern void     file_to_decimal();
185*7c478bd9Sstevel@tonic-gate extern void     func_to_decimal();
186*7c478bd9Sstevel@tonic-gate 
187*7c478bd9Sstevel@tonic-gate /* Definitions from 4.3 BSD math.h  4.6  9/11/85		 */
188*7c478bd9Sstevel@tonic-gate 
189*7c478bd9Sstevel@tonic-gate extern double   atof();
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate /* Definitions from System V				 */
192*7c478bd9Sstevel@tonic-gate 
193*7c478bd9Sstevel@tonic-gate extern int      errno;
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate extern double   strtod();
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate #endif				/* !_floatingpoint_h */
198