blob: 1935b611c61885b5114ff8b710d06ad98f9fd809 [file] [log] [blame]
Piotr Jasiukajtis25c28e832014-02-04 20:31:57 +01001/*
2 * CDDL HEADER START
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21/* Copyright (C) 1989 AT&T */
22/* All Rights Reserved */
23
24/*
25 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
26 */
27/*
28 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
29 * Use is subject to license terms.
30 */
31
32#ifndef _FLOATINGPOINT_H
33#define _FLOATINGPOINT_H
34
35#ifdef __STDC__
36#include <stdio_tag.h>
37#endif
38#include <sys/ieeefp.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/*
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.
50 */
51
52#ifndef __P
53#ifdef __STDC__
54#define __P(p) p
55#else
56#define __P(p) ()
57#endif
58#endif /* !defined(__P) */
59
60#if defined(__STDC__) && !defined(_FILEDEFED)
61#define _FILEDEFED
62typedef __FILE FILE;
63#endif
64
65#define N_IEEE_EXCEPTION 5 /* Number of floating-point exceptions. */
66
67typedef int sigfpe_code_type; /* Type of SIGFPE code. */
68
69typedef void (*sigfpe_handler_type)(); /* Pointer to exception handler */
70
71#define SIGFPE_DEFAULT (void (*)())0 /* default exception handling */
Marcel Telka6e270ca2017-07-02 04:55:09 +020072#define SIGFPE_IGNORE (void (*)())1 /* ignore this exception or code */
73#define SIGFPE_ABORT (void (*)())2 /* force abort on exception */
Piotr Jasiukajtis25c28e832014-02-04 20:31:57 +010074
75extern sigfpe_handler_type sigfpe __P((sigfpe_code_type, sigfpe_handler_type));
76
77/*
78 * Types for IEEE floating point.
79 */
80typedef float single;
81
82#ifndef _EXTENDED
83#define _EXTENDED
84typedef unsigned extended[3];
85#endif
86
87typedef long double quadruple; /* Quadruple-precision type. */
88
89typedef unsigned fp_exception_field_type;
90 /*
91 * A field containing fp_exceptions OR'ed
92 * together.
93 */
94/*
95 * Definitions for base conversion.
96 */
97#define DECIMAL_STRING_LENGTH 512 /* Size of buffer in decimal_record. */
98
99typedef char decimal_string[DECIMAL_STRING_LENGTH];
100 /* Decimal significand. */
101
102typedef 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. */
Marcel Telka6e270ca2017-07-02 04:55:09 +0200112 int ndigits; /* On fixed_form conversion from binary to */
Piotr Jasiukajtis25c28e832014-02-04 20:31:57 +0100113 /* decimal, contains number of digits */
114 /* required for ds. */
115} decimal_record;
116
117enum 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. */
124};
125
126typedef 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;
133
134enum 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! */
Marcel Telka6e270ca2017-07-02 04:55:09 +0200137 fixed_int_form, /* <digs> */
138 fixed_intdot_form, /* <digs>. */
Piotr Jasiukajtis25c28e832014-02-04 20:31:57 +0100139 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) */
149};
150
151extern void single_to_decimal __P((single *, decimal_mode *, decimal_record *,
152 fp_exception_field_type *));
153extern void double_to_decimal __P((double *, decimal_mode *, decimal_record *,
154 fp_exception_field_type *));
155extern void extended_to_decimal __P((extended *, decimal_mode *,
156 decimal_record *, fp_exception_field_type *));
157extern void quadruple_to_decimal __P((quadruple *, decimal_mode *,
158 decimal_record *, fp_exception_field_type *));
159
160extern void decimal_to_single __P((single *, decimal_mode *, decimal_record *,
161 fp_exception_field_type *));
162extern void decimal_to_double __P((double *, decimal_mode *, decimal_record *,
163 fp_exception_field_type *));
164extern void decimal_to_extended __P((extended *, decimal_mode *,
165 decimal_record *, fp_exception_field_type *));
166extern void decimal_to_quadruple __P((quadruple *, decimal_mode *,
167 decimal_record *, fp_exception_field_type *));
168
169extern void string_to_decimal __P((char **, int, int, decimal_record *,
170 enum decimal_string_form *, char **));
171extern void func_to_decimal __P((char **, int, int, decimal_record *,
172 enum decimal_string_form *, char **,
173 int (*)(void), int *, int (*)(int)));
174extern void file_to_decimal __P((char **, int, int, decimal_record *,
175 enum decimal_string_form *, char **,
176 FILE *, int *));
177
178extern char *seconvert __P((single *, int, int *, int *, char *));
179extern char *sfconvert __P((single *, int, int *, int *, char *));
180extern char *sgconvert __P((single *, int, int, char *));
181extern char *econvert __P((double, int, int *, int *, char *));
182extern char *fconvert __P((double, int, int *, int *, char *));
183extern char *gconvert __P((double, int, int, char *));
184extern char *qeconvert __P((quadruple *, int, int *, int *, char *));
185extern char *qfconvert __P((quadruple *, int, int *, int *, char *));
186extern char *qgconvert __P((quadruple *, int, int, char *));
187
188extern char *ecvt __P((double, int, int *, int *));
189extern char *fcvt __P((double, int, int *, int *));
190extern char *gcvt __P((double, int, char *));
191
192#if __cplusplus >= 199711L
193namespace std {
194#endif
195/*
196 * ANSI C Standard says the following entry points should be
197 * prototyped in <stdlib.h>. They are now, but weren't before.
198 */
199extern double atof __P((const char *));
200extern double strtod __P((const char *, char **));
201#if __cplusplus >= 199711L
202}
203
204using std::atof;
205using std::strtod;
206#endif /* end of namespace std */
207
208#ifdef __cplusplus
209}
210#endif
211
212#endif /* _FLOATINGPOINT_H */