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