xref: /titanic_44/usr/src/head/floatingpoint.h (revision 25c28e83beb90e7c80452a7c818c5e6f73a07dc8)
1*25c28e83SPiotr Jasiukajtis /*
2*25c28e83SPiotr Jasiukajtis  * CDDL HEADER START
3*25c28e83SPiotr Jasiukajtis  *
4*25c28e83SPiotr Jasiukajtis  * The contents of this file are subject to the terms of the
5*25c28e83SPiotr Jasiukajtis  * Common Development and Distribution License (the "License").
6*25c28e83SPiotr Jasiukajtis  * You may not use this file except in compliance with the License.
7*25c28e83SPiotr Jasiukajtis  *
8*25c28e83SPiotr Jasiukajtis  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*25c28e83SPiotr Jasiukajtis  * or http://www.opensolaris.org/os/licensing.
10*25c28e83SPiotr Jasiukajtis  * See the License for the specific language governing permissions
11*25c28e83SPiotr Jasiukajtis  * and limitations under the License.
12*25c28e83SPiotr Jasiukajtis  *
13*25c28e83SPiotr Jasiukajtis  * When distributing Covered Code, include this CDDL HEADER in each
14*25c28e83SPiotr Jasiukajtis  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*25c28e83SPiotr Jasiukajtis  * If applicable, add the following below this CDDL HEADER, with the
16*25c28e83SPiotr Jasiukajtis  * fields enclosed by brackets "[]" replaced with your own identifying
17*25c28e83SPiotr Jasiukajtis  * information: Portions Copyright [yyyy] [name of copyright owner]
18*25c28e83SPiotr Jasiukajtis  *
19*25c28e83SPiotr Jasiukajtis  * CDDL HEADER END
20*25c28e83SPiotr Jasiukajtis  */
21*25c28e83SPiotr Jasiukajtis /*	Copyright (C) 1989 AT&T	*/
22*25c28e83SPiotr Jasiukajtis /*	  All Rights Reserved */
23*25c28e83SPiotr Jasiukajtis 
24*25c28e83SPiotr Jasiukajtis /*
25*25c28e83SPiotr Jasiukajtis  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
26*25c28e83SPiotr Jasiukajtis  */
27*25c28e83SPiotr Jasiukajtis /*
28*25c28e83SPiotr Jasiukajtis  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
29*25c28e83SPiotr Jasiukajtis  * Use is subject to license terms.
30*25c28e83SPiotr Jasiukajtis  */
31*25c28e83SPiotr Jasiukajtis 
32*25c28e83SPiotr Jasiukajtis #ifndef _FLOATINGPOINT_H
33*25c28e83SPiotr Jasiukajtis #define	_FLOATINGPOINT_H
34*25c28e83SPiotr Jasiukajtis 
35*25c28e83SPiotr Jasiukajtis #ifdef __STDC__
36*25c28e83SPiotr Jasiukajtis #include <stdio_tag.h>
37*25c28e83SPiotr Jasiukajtis #endif
38*25c28e83SPiotr Jasiukajtis #include <sys/ieeefp.h>
39*25c28e83SPiotr Jasiukajtis 
40*25c28e83SPiotr Jasiukajtis #ifdef __cplusplus
41*25c28e83SPiotr Jasiukajtis extern "C" {
42*25c28e83SPiotr Jasiukajtis #endif
43*25c28e83SPiotr Jasiukajtis 
44*25c28e83SPiotr Jasiukajtis /*
45*25c28e83SPiotr Jasiukajtis  * <floatingpoint.h> contains definitions for constants, types, variables,
46*25c28e83SPiotr Jasiukajtis  * and functions for:
47*25c28e83SPiotr Jasiukajtis  *	IEEE floating-point arithmetic base conversion;
48*25c28e83SPiotr Jasiukajtis  *	IEEE floating-point arithmetic modes;
49*25c28e83SPiotr Jasiukajtis  *	IEEE floating-point arithmetic exception handling.
50*25c28e83SPiotr Jasiukajtis  */
51*25c28e83SPiotr Jasiukajtis 
52*25c28e83SPiotr Jasiukajtis #ifndef __P
53*25c28e83SPiotr Jasiukajtis #ifdef __STDC__
54*25c28e83SPiotr Jasiukajtis #define	__P(p)	p
55*25c28e83SPiotr Jasiukajtis #else
56*25c28e83SPiotr Jasiukajtis #define	__P(p)	()
57*25c28e83SPiotr Jasiukajtis #endif
58*25c28e83SPiotr Jasiukajtis #endif	/* !defined(__P) */
59*25c28e83SPiotr Jasiukajtis 
60*25c28e83SPiotr Jasiukajtis #if defined(__STDC__) && !defined(_FILEDEFED)
61*25c28e83SPiotr Jasiukajtis #define	_FILEDEFED
62*25c28e83SPiotr Jasiukajtis typedef	__FILE FILE;
63*25c28e83SPiotr Jasiukajtis #endif
64*25c28e83SPiotr Jasiukajtis 
65*25c28e83SPiotr Jasiukajtis #define	N_IEEE_EXCEPTION 5	/* Number of floating-point exceptions. */
66*25c28e83SPiotr Jasiukajtis 
67*25c28e83SPiotr Jasiukajtis typedef int sigfpe_code_type;	/* Type of SIGFPE code. */
68*25c28e83SPiotr Jasiukajtis 
69*25c28e83SPiotr Jasiukajtis typedef void (*sigfpe_handler_type)();	/* Pointer to exception handler */
70*25c28e83SPiotr Jasiukajtis 
71*25c28e83SPiotr Jasiukajtis #define	SIGFPE_DEFAULT (void (*)())0	/* default exception handling */
72*25c28e83SPiotr Jasiukajtis #define	SIGFPE_IGNORE  (void (*)())1  	/* ignore this exception or code */
73*25c28e83SPiotr Jasiukajtis #define	SIGFPE_ABORT   (void (*)())2  	/* force abort on exception */
74*25c28e83SPiotr Jasiukajtis 
75*25c28e83SPiotr Jasiukajtis extern sigfpe_handler_type sigfpe __P((sigfpe_code_type, sigfpe_handler_type));
76*25c28e83SPiotr Jasiukajtis 
77*25c28e83SPiotr Jasiukajtis /*
78*25c28e83SPiotr Jasiukajtis  * Types for IEEE floating point.
79*25c28e83SPiotr Jasiukajtis  */
80*25c28e83SPiotr Jasiukajtis typedef float single;
81*25c28e83SPiotr Jasiukajtis 
82*25c28e83SPiotr Jasiukajtis #ifndef _EXTENDED
83*25c28e83SPiotr Jasiukajtis #define	_EXTENDED
84*25c28e83SPiotr Jasiukajtis typedef unsigned extended[3];
85*25c28e83SPiotr Jasiukajtis #endif
86*25c28e83SPiotr Jasiukajtis 
87*25c28e83SPiotr Jasiukajtis typedef long double quadruple;	/* Quadruple-precision type. */
88*25c28e83SPiotr Jasiukajtis 
89*25c28e83SPiotr Jasiukajtis typedef unsigned fp_exception_field_type;
90*25c28e83SPiotr Jasiukajtis 				/*
91*25c28e83SPiotr Jasiukajtis 				 * A field containing fp_exceptions OR'ed
92*25c28e83SPiotr Jasiukajtis 				 * together.
93*25c28e83SPiotr Jasiukajtis 				 */
94*25c28e83SPiotr Jasiukajtis /*
95*25c28e83SPiotr Jasiukajtis  * Definitions for base conversion.
96*25c28e83SPiotr Jasiukajtis  */
97*25c28e83SPiotr Jasiukajtis #define	DECIMAL_STRING_LENGTH 512	/* Size of buffer in decimal_record. */
98*25c28e83SPiotr Jasiukajtis 
99*25c28e83SPiotr Jasiukajtis typedef char decimal_string[DECIMAL_STRING_LENGTH];
100*25c28e83SPiotr Jasiukajtis 				/* Decimal significand. */
101*25c28e83SPiotr Jasiukajtis 
102*25c28e83SPiotr Jasiukajtis typedef struct {
103*25c28e83SPiotr Jasiukajtis 	enum fp_class_type fpclass;
104*25c28e83SPiotr Jasiukajtis 	int	sign;
105*25c28e83SPiotr Jasiukajtis 	int	exponent;
106*25c28e83SPiotr Jasiukajtis 	decimal_string ds;	/* Significand - each char contains an ascii */
107*25c28e83SPiotr Jasiukajtis 				/* digit, except the string-terminating */
108*25c28e83SPiotr Jasiukajtis 				/* ascii null. */
109*25c28e83SPiotr Jasiukajtis 	int	more;		/* On conversion from decimal to binary, != 0 */
110*25c28e83SPiotr Jasiukajtis 				/* indicates more non-zero digits following */
111*25c28e83SPiotr Jasiukajtis 				/* ds. */
112*25c28e83SPiotr Jasiukajtis 	int 	ndigits;	/* On fixed_form conversion from binary to */
113*25c28e83SPiotr Jasiukajtis 				/* decimal, contains number of digits */
114*25c28e83SPiotr Jasiukajtis 				/* required for ds. */
115*25c28e83SPiotr Jasiukajtis } decimal_record;
116*25c28e83SPiotr Jasiukajtis 
117*25c28e83SPiotr Jasiukajtis enum decimal_form {
118*25c28e83SPiotr Jasiukajtis 	fixed_form,		/* Fortran F format: ndigits specifies number */
119*25c28e83SPiotr Jasiukajtis 				/* of digits after point; if negative, */
120*25c28e83SPiotr Jasiukajtis 				/* specifies rounding to occur to left of */
121*25c28e83SPiotr Jasiukajtis 				/* point. */
122*25c28e83SPiotr Jasiukajtis 	floating_form		/* Fortran E format: ndigits specifies number */
123*25c28e83SPiotr Jasiukajtis 				/* of significant digits. */
124*25c28e83SPiotr Jasiukajtis };
125*25c28e83SPiotr Jasiukajtis 
126*25c28e83SPiotr Jasiukajtis typedef struct {
127*25c28e83SPiotr Jasiukajtis 	enum fp_direction_type rd;
128*25c28e83SPiotr Jasiukajtis 				/* Rounding direction. */
129*25c28e83SPiotr Jasiukajtis 	enum decimal_form df;	/* Format for conversion from binary to */
130*25c28e83SPiotr Jasiukajtis 				/* decimal. */
131*25c28e83SPiotr Jasiukajtis 	int ndigits;		/* Number of digits for conversion. */
132*25c28e83SPiotr Jasiukajtis } decimal_mode;
133*25c28e83SPiotr Jasiukajtis 
134*25c28e83SPiotr Jasiukajtis enum decimal_string_form {	/* Valid decimal number string formats. */
135*25c28e83SPiotr Jasiukajtis 	invalid_form,		/* Not a valid decimal string format. */
136*25c28e83SPiotr Jasiukajtis 	whitespace_form,	/* All white space - valid in Fortran! */
137*25c28e83SPiotr Jasiukajtis 	fixed_int_form,		/* <digs> 		*/
138*25c28e83SPiotr Jasiukajtis 	fixed_intdot_form,	/* <digs>. 		*/
139*25c28e83SPiotr Jasiukajtis 	fixed_dotfrac_form,	/* .<digs>		*/
140*25c28e83SPiotr Jasiukajtis 	fixed_intdotfrac_form,	/* <digs>.<frac>	*/
141*25c28e83SPiotr Jasiukajtis 	floating_int_form,	/* <digs><exp>		*/
142*25c28e83SPiotr Jasiukajtis 	floating_intdot_form,	/* <digs>.<exp>		*/
143*25c28e83SPiotr Jasiukajtis 	floating_dotfrac_form,	/* .<digs><exp>		*/
144*25c28e83SPiotr Jasiukajtis 	floating_intdotfrac_form, /* <digs>.<digs><exp>	*/
145*25c28e83SPiotr Jasiukajtis 	inf_form,		/* inf			*/
146*25c28e83SPiotr Jasiukajtis 	infinity_form,		/* infinity		*/
147*25c28e83SPiotr Jasiukajtis 	nan_form,		/* nan			*/
148*25c28e83SPiotr Jasiukajtis 	nanstring_form		/* nan(string)		*/
149*25c28e83SPiotr Jasiukajtis };
150*25c28e83SPiotr Jasiukajtis 
151*25c28e83SPiotr Jasiukajtis extern void single_to_decimal __P((single *, decimal_mode *, decimal_record *,
152*25c28e83SPiotr Jasiukajtis 				fp_exception_field_type *));
153*25c28e83SPiotr Jasiukajtis extern void double_to_decimal __P((double *, decimal_mode *, decimal_record *,
154*25c28e83SPiotr Jasiukajtis 				fp_exception_field_type *));
155*25c28e83SPiotr Jasiukajtis extern void extended_to_decimal __P((extended *, decimal_mode *,
156*25c28e83SPiotr Jasiukajtis 				decimal_record *, fp_exception_field_type *));
157*25c28e83SPiotr Jasiukajtis extern void quadruple_to_decimal __P((quadruple *, decimal_mode *,
158*25c28e83SPiotr Jasiukajtis 				decimal_record *, fp_exception_field_type *));
159*25c28e83SPiotr Jasiukajtis 
160*25c28e83SPiotr Jasiukajtis extern void decimal_to_single __P((single *, decimal_mode *, decimal_record *,
161*25c28e83SPiotr Jasiukajtis 				fp_exception_field_type *));
162*25c28e83SPiotr Jasiukajtis extern void decimal_to_double __P((double *, decimal_mode *, decimal_record *,
163*25c28e83SPiotr Jasiukajtis 				fp_exception_field_type *));
164*25c28e83SPiotr Jasiukajtis extern void decimal_to_extended __P((extended *, decimal_mode *,
165*25c28e83SPiotr Jasiukajtis 				decimal_record *, fp_exception_field_type *));
166*25c28e83SPiotr Jasiukajtis extern void decimal_to_quadruple __P((quadruple *, decimal_mode *,
167*25c28e83SPiotr Jasiukajtis 				decimal_record *, fp_exception_field_type *));
168*25c28e83SPiotr Jasiukajtis 
169*25c28e83SPiotr Jasiukajtis extern void string_to_decimal __P((char **, int, int, decimal_record *,
170*25c28e83SPiotr Jasiukajtis 				enum decimal_string_form *, char **));
171*25c28e83SPiotr Jasiukajtis extern void func_to_decimal __P((char **, int, int, decimal_record *,
172*25c28e83SPiotr Jasiukajtis 				enum decimal_string_form *, char **,
173*25c28e83SPiotr Jasiukajtis 				int (*)(void), int *, int (*)(int)));
174*25c28e83SPiotr Jasiukajtis extern void file_to_decimal __P((char **, int, int, decimal_record *,
175*25c28e83SPiotr Jasiukajtis 				enum decimal_string_form *, char **,
176*25c28e83SPiotr Jasiukajtis 				FILE *, int *));
177*25c28e83SPiotr Jasiukajtis 
178*25c28e83SPiotr Jasiukajtis extern char *seconvert __P((single *, int, int *, int *, char *));
179*25c28e83SPiotr Jasiukajtis extern char *sfconvert __P((single *, int, int *, int *, char *));
180*25c28e83SPiotr Jasiukajtis extern char *sgconvert __P((single *, int, int, char *));
181*25c28e83SPiotr Jasiukajtis extern char *econvert __P((double, int, int *, int *, char *));
182*25c28e83SPiotr Jasiukajtis extern char *fconvert __P((double, int, int *, int *, char *));
183*25c28e83SPiotr Jasiukajtis extern char *gconvert __P((double, int, int, char *));
184*25c28e83SPiotr Jasiukajtis extern char *qeconvert __P((quadruple *, int, int *, int *, char *));
185*25c28e83SPiotr Jasiukajtis extern char *qfconvert __P((quadruple *, int, int *, int *, char *));
186*25c28e83SPiotr Jasiukajtis extern char *qgconvert __P((quadruple *, int, int, char *));
187*25c28e83SPiotr Jasiukajtis 
188*25c28e83SPiotr Jasiukajtis extern char *ecvt __P((double, int, int *, int *));
189*25c28e83SPiotr Jasiukajtis extern char *fcvt __P((double, int, int *, int *));
190*25c28e83SPiotr Jasiukajtis extern char *gcvt __P((double, int, char *));
191*25c28e83SPiotr Jasiukajtis 
192*25c28e83SPiotr Jasiukajtis #if __cplusplus >= 199711L
193*25c28e83SPiotr Jasiukajtis namespace std {
194*25c28e83SPiotr Jasiukajtis #endif
195*25c28e83SPiotr Jasiukajtis /*
196*25c28e83SPiotr Jasiukajtis  * ANSI C Standard says the following entry points should be
197*25c28e83SPiotr Jasiukajtis  * prototyped in <stdlib.h>.  They are now, but weren't before.
198*25c28e83SPiotr Jasiukajtis  */
199*25c28e83SPiotr Jasiukajtis extern double atof __P((const char *));
200*25c28e83SPiotr Jasiukajtis extern double strtod __P((const char *, char **));
201*25c28e83SPiotr Jasiukajtis #if __cplusplus >= 199711L
202*25c28e83SPiotr Jasiukajtis }
203*25c28e83SPiotr Jasiukajtis 
204*25c28e83SPiotr Jasiukajtis using std::atof;
205*25c28e83SPiotr Jasiukajtis using std::strtod;
206*25c28e83SPiotr Jasiukajtis #endif /* end of namespace std */
207*25c28e83SPiotr Jasiukajtis 
208*25c28e83SPiotr Jasiukajtis #ifdef __cplusplus
209*25c28e83SPiotr Jasiukajtis }
210*25c28e83SPiotr Jasiukajtis #endif
211*25c28e83SPiotr Jasiukajtis 
212*25c28e83SPiotr Jasiukajtis #endif /* _FLOATINGPOINT_H */
213