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