gdtoa.h revision 1.9 1 /* $NetBSD: gdtoa.h,v 1.9 2011/03/20 23:15:35 christos Exp $ */
2
3 /****************************************************************
4
5 The author of this software is David M. Gay.
6
7 Copyright (C) 1998 by Lucent Technologies
8 All Rights Reserved
9
10 Permission to use, copy, modify, and distribute this software and
11 its documentation for any purpose and without fee is hereby
12 granted, provided that the above copyright notice appear in all
13 copies and that both that the copyright notice and this
14 permission notice and warranty disclaimer appear in supporting
15 documentation, and that the name of Lucent or any of its entities
16 not be used in advertising or publicity pertaining to
17 distribution of the software without specific, written prior
18 permission.
19
20 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
21 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
22 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
23 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
24 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
25 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
26 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
27 THIS SOFTWARE.
28
29 ****************************************************************/
30
31 /* Please send bug reports to David M. Gay (dmg at acm dot org,
32 * with " at " changed at "@" and " dot " changed to "."). */
33
34 #ifndef GDTOA_H_INCLUDED
35 #define GDTOA_H_INCLUDED
36
37 #include "arith.h"
38 #include <stddef.h> /* for size_t */
39 #include <stdint.h>
40
41 #ifndef Long
42 #define Long int32_t
43 #endif
44 #ifndef ULong
45 #define ULong uint32_t
46 #endif
47 #ifndef UShort
48 #define UShort uint16_t
49 #endif
50
51 #ifndef ANSI
52 #ifdef KR_headers
53 #define ANSI(x) ()
54 #define Void /*nothing*/
55 #else
56 #define ANSI(x) x
57 #define Void void
58 #endif
59 #endif /* ANSI */
60
61 #ifndef CONST
62 #ifdef KR_headers
63 #define CONST /* blank */
64 #else
65 #define CONST const
66 #endif
67 #endif /* CONST */
68
69 enum { /* return values from strtodg */
70 STRTOG_Zero = 0,
71 STRTOG_Normal = 1,
72 STRTOG_Denormal = 2,
73 STRTOG_Infinite = 3,
74 STRTOG_NaN = 4,
75 STRTOG_NaNbits = 5,
76 STRTOG_NoNumber = 6,
77 STRTOG_Retmask = 7,
78
79 /* The following may be or-ed into one of the above values. */
80
81 STRTOG_Neg = 0x08, /* does not affect STRTOG_Inexlo or STRTOG_Inexhi */
82 STRTOG_Inexlo = 0x10, /* returned result rounded toward zero */
83 STRTOG_Inexhi = 0x20, /* returned result rounded away from zero */
84 STRTOG_Inexact = 0x30,
85 STRTOG_Underflow= 0x40,
86 STRTOG_Overflow = 0x80,
87 STRTOG_NoMemory = 0x100
88 };
89
90 typedef struct
91 FPI {
92 int nbits;
93 int emin;
94 int emax;
95 int rounding;
96 int sudden_underflow;
97 } FPI;
98
99 enum { /* FPI.rounding values: same as FLT_ROUNDS */
100 FPI_Round_zero = 0,
101 FPI_Round_near = 1,
102 FPI_Round_up = 2,
103 FPI_Round_down = 3
104 };
105
106 #ifdef __cplusplus
107 extern "C" {
108 #endif
109
110 #define dtoa __dtoa
111 #define gdtoa __gdtoa
112 #define ldtoa __ldtoa
113 #define hldtoa __hldtoa
114 #define hdtoa __hdtoa
115 #define freedtoa __freedtoa
116 #define strtodg __strtodg_D2A
117 #define strtopQ __strtopQ_D2A
118 #define strtopx __strtopx_D2A
119 #define strtopxL __strtopxL_D2A
120 #define strtord __strtord_D2A
121
122 extern char* dtoa ANSI((double d, int mode, int ndigits, int *decpt,
123 int *sign, char **rve));
124 extern char* hdtoa ANSI((double d, const char *xdigs, int ndigits, int *decpt,
125 int *sign, char **rve));
126 extern char* ldtoa ANSI((long double *ld, int mode, int ndigits, int *decpt,
127 int *sign, char **rve));
128 extern char* hldtoa ANSI((long double e, const char *xdigs, int ndigits,
129 int *decpt, int *sign, char **rve));
130
131 extern char* gdtoa ANSI((FPI *fpi, int be, ULong *bits, int *kindp,
132 int mode, int ndigits, int *decpt, char **rve));
133 extern void freedtoa ANSI((char*));
134 extern float strtof ANSI((CONST char *, char **));
135 extern double strtod ANSI((CONST char *, char **));
136 extern int strtodg ANSI((CONST char*, char**, CONST FPI*, Long*, ULong*));
137
138 extern char* g_ddfmt ANSI((char*, double*, int, size_t));
139 extern char* g_dfmt ANSI((char*, double*, int, size_t));
140 extern char* g_ffmt ANSI((char*, float*, int, size_t));
141 extern char* g_Qfmt ANSI((char*, void*, int, size_t));
142 extern char* g_xfmt ANSI((char*, void*, int, size_t));
143 extern char* g_xLfmt ANSI((char*, void*, int, size_t));
144
145 extern int strtoId ANSI((CONST char*, char**, double*, double*));
146 extern int strtoIdd ANSI((CONST char*, char**, double*, double*));
147 extern int strtoIf ANSI((CONST char*, char**, float*, float*));
148 extern int strtoIQ ANSI((CONST char*, char**, void*, void*));
149 extern int strtoIx ANSI((CONST char*, char**, void*, void*));
150 extern int strtoIxL ANSI((CONST char*, char**, void*, void*));
151 extern int strtord ANSI((CONST char*, char**, int, double*));
152 extern int strtordd ANSI((CONST char*, char**, int, double*));
153 extern int strtorf ANSI((CONST char*, char**, int, float*));
154 extern int strtorQ ANSI((CONST char*, char**, int, void*));
155 extern int strtorx ANSI((CONST char*, char**, int, void*));
156 extern int strtorxL ANSI((CONST char*, char**, int, void*));
157 #if 1
158 extern int strtodI ANSI((CONST char*, char**, double*));
159 extern int strtopd ANSI((CONST char*, char**, double*));
160 extern int strtopdd ANSI((CONST char*, char**, double*));
161 extern int strtopf ANSI((CONST char*, char**, float*));
162 extern int strtopQ ANSI((CONST char*, char**, void*));
163 extern int strtopx ANSI((CONST char*, char**, void*));
164 extern int strtopxL ANSI((CONST char*, char**, void*));
165 #else
166 #define strtopd(s,se,x) strtord(s,se,1,x)
167 #define strtopdd(s,se,x) strtordd(s,se,1,x)
168 #define strtopf(s,se,x) strtorf(s,se,1,x)
169 #define strtopQ(s,se,x) strtorQ(s,se,1,x)
170 #define strtopx(s,se,x) strtorx(s,se,1,x)
171 #define strtopxL(s,se,x) strtorxL(s,se,1,x)
172 #endif
173
174 #ifdef __cplusplus
175 }
176 #endif
177 #endif /* GDTOA_H_INCLUDED */
178