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