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