xref: /netbsd-src/lib/libc/gdtoa/gdtoa.h (revision 9a9a41227b42868f516d4f928b32562ad0f5bc3b)
1*9a9a4122Sriastradh /* $NetBSD: gdtoa.h,v 1.11 2019/08/01 02:27:43 riastradh Exp $ */
27684d5e0Skleink 
37684d5e0Skleink /****************************************************************
47684d5e0Skleink 
57684d5e0Skleink The author of this software is David M. Gay.
67684d5e0Skleink 
77684d5e0Skleink Copyright (C) 1998 by Lucent Technologies
87684d5e0Skleink All Rights Reserved
97684d5e0Skleink 
107684d5e0Skleink Permission to use, copy, modify, and distribute this software and
117684d5e0Skleink its documentation for any purpose and without fee is hereby
127684d5e0Skleink granted, provided that the above copyright notice appear in all
137684d5e0Skleink copies and that both that the copyright notice and this
147684d5e0Skleink permission notice and warranty disclaimer appear in supporting
157684d5e0Skleink documentation, and that the name of Lucent or any of its entities
167684d5e0Skleink not be used in advertising or publicity pertaining to
177684d5e0Skleink distribution of the software without specific, written prior
187684d5e0Skleink permission.
197684d5e0Skleink 
207684d5e0Skleink LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
217684d5e0Skleink INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
227684d5e0Skleink IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
237684d5e0Skleink SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
247684d5e0Skleink WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
257684d5e0Skleink IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
267684d5e0Skleink ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
277684d5e0Skleink THIS SOFTWARE.
287684d5e0Skleink 
297684d5e0Skleink ****************************************************************/
307684d5e0Skleink 
317684d5e0Skleink /* Please send bug reports to David M. Gay (dmg at acm dot org,
327684d5e0Skleink  * with " at " changed at "@" and " dot " changed to ".").	*/
337684d5e0Skleink 
347684d5e0Skleink #ifndef GDTOA_H_INCLUDED
357684d5e0Skleink #define GDTOA_H_INCLUDED
367684d5e0Skleink 
377684d5e0Skleink #include "arith.h"
3861e56760Schristos #include <stddef.h> /* for size_t */
3961e56760Schristos #include <stdint.h>
407684d5e0Skleink 
41c99aac45Sjoerg #ifndef __LOCALE_T_DECLARED
42c99aac45Sjoerg typedef struct _locale		*locale_t;
43c99aac45Sjoerg #define __LOCALE_T_DECLARED
44c99aac45Sjoerg #endif
45c99aac45Sjoerg 
467684d5e0Skleink #ifndef Long
47fc716ffaSchristos #define Long int32_t
487684d5e0Skleink #endif
497684d5e0Skleink #ifndef ULong
50fc716ffaSchristos #define ULong uint32_t
517684d5e0Skleink #endif
527684d5e0Skleink #ifndef UShort
53fc716ffaSchristos #define UShort uint16_t
547684d5e0Skleink #endif
557684d5e0Skleink 
567684d5e0Skleink #ifndef ANSI
577684d5e0Skleink #ifdef KR_headers
587684d5e0Skleink #define ANSI(x) ()
597684d5e0Skleink #define Void /*nothing*/
607684d5e0Skleink #else
617684d5e0Skleink #define ANSI(x) x
627684d5e0Skleink #define Void void
637684d5e0Skleink #endif
647684d5e0Skleink #endif /* ANSI */
657684d5e0Skleink 
667684d5e0Skleink #ifndef CONST
677684d5e0Skleink #ifdef KR_headers
687684d5e0Skleink #define CONST /* blank */
697684d5e0Skleink #else
707684d5e0Skleink #define CONST const
717684d5e0Skleink #endif
727684d5e0Skleink #endif /* CONST */
737684d5e0Skleink 
747684d5e0Skleink  enum {	/* return values from strtodg */
757684d5e0Skleink 	STRTOG_Zero	= 0,
767684d5e0Skleink 	STRTOG_Normal	= 1,
777684d5e0Skleink 	STRTOG_Denormal	= 2,
787684d5e0Skleink 	STRTOG_Infinite	= 3,
797684d5e0Skleink 	STRTOG_NaN	= 4,
807684d5e0Skleink 	STRTOG_NaNbits	= 5,
817684d5e0Skleink 	STRTOG_NoNumber	= 6,
827684d5e0Skleink 	STRTOG_Retmask	= 7,
837684d5e0Skleink 
847684d5e0Skleink 	/* The following may be or-ed into one of the above values. */
857684d5e0Skleink 
8661e56760Schristos 	STRTOG_Neg	= 0x08, /* does not affect STRTOG_Inexlo or STRTOG_Inexhi */
8761e56760Schristos 	STRTOG_Inexlo	= 0x10,	/* returned result rounded toward zero */
8861e56760Schristos 	STRTOG_Inexhi	= 0x20, /* returned result rounded away from zero */
897684d5e0Skleink 	STRTOG_Inexact	= 0x30,
907684d5e0Skleink 	STRTOG_Underflow= 0x40,
91ab625449Schristos 	STRTOG_Overflow	= 0x80,
92ab625449Schristos 	STRTOG_NoMemory = 0x100
937684d5e0Skleink 	};
947684d5e0Skleink 
957684d5e0Skleink  typedef struct
967684d5e0Skleink FPI {
977684d5e0Skleink 	int nbits;
987684d5e0Skleink 	int emin;
997684d5e0Skleink 	int emax;
1007684d5e0Skleink 	int rounding;
1017684d5e0Skleink 	int sudden_underflow;
1027684d5e0Skleink 	} FPI;
1037684d5e0Skleink 
1047684d5e0Skleink enum {	/* FPI.rounding values: same as FLT_ROUNDS */
1057684d5e0Skleink 	FPI_Round_zero = 0,
1067684d5e0Skleink 	FPI_Round_near = 1,
1077684d5e0Skleink 	FPI_Round_up = 2,
1087684d5e0Skleink 	FPI_Round_down = 3
1097684d5e0Skleink 	};
1107684d5e0Skleink 
1117684d5e0Skleink #ifdef __cplusplus
1127684d5e0Skleink extern "C" {
1137684d5e0Skleink #endif
1147684d5e0Skleink 
115ac898a26Skleink #define	dtoa		__dtoa
1169ad66572Schristos #define	gdtoa		__gdtoa
1179ad66572Schristos #define	ldtoa		__ldtoa
1189ad66572Schristos #define	hldtoa		__hldtoa
1199ad66572Schristos #define	hdtoa		__hdtoa
120ac898a26Skleink #define	freedtoa	__freedtoa
121ce9a62e9Skleink #define	strtodg		__strtodg_D2A
122bc89c06cSkleink #define	strtopQ		__strtopQ_D2A
123bc89c06cSkleink #define	strtopx		__strtopx_D2A
124bc89c06cSkleink #define	strtopxL	__strtopxL_D2A
125ac898a26Skleink #define	strtord		__strtord_D2A
126ac898a26Skleink 
1277684d5e0Skleink extern char* dtoa  ANSI((double d, int mode, int ndigits, int *decpt,
1287684d5e0Skleink 			int *sign, char **rve));
1299ad66572Schristos extern char* hdtoa ANSI((double d, const char *xdigs, int ndigits, int *decpt,
1309ad66572Schristos 			int *sign, char **rve));
1319ad66572Schristos extern char* ldtoa ANSI((long double *ld, int mode, int ndigits, int *decpt,
1329ad66572Schristos 			int *sign, char **rve));
1339ad66572Schristos extern char* hldtoa ANSI((long double e, const char *xdigs, int ndigits,
1349ad66572Schristos 			int *decpt, int *sign, char **rve));
1359ad66572Schristos 
136*9a9a4122Sriastradh extern char* gdtoa ANSI((CONST FPI *fpi, int be, ULong *bits, int *kindp,
1377684d5e0Skleink 			int mode, int ndigits, int *decpt, char **rve));
1387684d5e0Skleink extern void freedtoa ANSI((char*));
1397684d5e0Skleink extern float  strtof ANSI((CONST char *, char **));
1407684d5e0Skleink extern double strtod ANSI((CONST char *, char **));
141c99aac45Sjoerg extern int strtodg ANSI((CONST char*, char**, CONST FPI*, Long*, ULong*,
142c99aac45Sjoerg                          locale_t));
1437684d5e0Skleink 
14461e56760Schristos extern char*	g_ddfmt  ANSI((char*, double*, int, size_t));
14561e56760Schristos extern char*	g_dfmt   ANSI((char*, double*, int, size_t));
14661e56760Schristos extern char*	g_ffmt   ANSI((char*, float*,  int, size_t));
14761e56760Schristos extern char*	g_Qfmt   ANSI((char*, void*,   int, size_t));
14861e56760Schristos extern char*	g_xfmt   ANSI((char*, void*,   int, size_t));
14961e56760Schristos extern char*	g_xLfmt  ANSI((char*, void*,   int, size_t));
1507684d5e0Skleink 
1517684d5e0Skleink extern int	strtoId  ANSI((CONST char*, char**, double*, double*));
1527684d5e0Skleink extern int	strtoIdd ANSI((CONST char*, char**, double*, double*));
1537684d5e0Skleink extern int	strtoIf  ANSI((CONST char*, char**, float*, float*));
1547684d5e0Skleink extern int	strtoIQ  ANSI((CONST char*, char**, void*, void*));
1557684d5e0Skleink extern int	strtoIx  ANSI((CONST char*, char**, void*, void*));
1567684d5e0Skleink extern int	strtoIxL ANSI((CONST char*, char**, void*, void*));
157c99aac45Sjoerg extern int	strtord  ANSI((CONST char*, char**, int, double*, locale_t));
1587684d5e0Skleink extern int	strtordd ANSI((CONST char*, char**, int, double*));
1597684d5e0Skleink extern int	strtorf  ANSI((CONST char*, char**, int, float*));
1607684d5e0Skleink extern int	strtorQ  ANSI((CONST char*, char**, int, void*));
1617684d5e0Skleink extern int	strtorx  ANSI((CONST char*, char**, int, void*));
1627684d5e0Skleink extern int	strtorxL ANSI((CONST char*, char**, int, void*));
1637684d5e0Skleink #if 1
1647684d5e0Skleink extern int	strtodI  ANSI((CONST char*, char**, double*));
1657684d5e0Skleink extern int	strtopd  ANSI((CONST char*, char**, double*));
1667684d5e0Skleink extern int	strtopdd ANSI((CONST char*, char**, double*));
1677684d5e0Skleink extern int	strtopf  ANSI((CONST char*, char**, float*));
168c99aac45Sjoerg extern int	strtopQ  ANSI((CONST char*, char**, void*, locale_t));
169c99aac45Sjoerg extern int	strtopx  ANSI((CONST char*, char**, void*, locale_t));
170c99aac45Sjoerg extern int	strtopxL ANSI((CONST char*, char**, void*, locale_t));
1717684d5e0Skleink #else
1727684d5e0Skleink #define strtopd(s,se,x) strtord(s,se,1,x)
1737684d5e0Skleink #define strtopdd(s,se,x) strtordd(s,se,1,x)
1747684d5e0Skleink #define strtopf(s,se,x) strtorf(s,se,1,x)
1757684d5e0Skleink #define strtopQ(s,se,x) strtorQ(s,se,1,x)
1767684d5e0Skleink #define strtopx(s,se,x) strtorx(s,se,1,x)
1777684d5e0Skleink #define strtopxL(s,se,x) strtorxL(s,se,1,x)
1787684d5e0Skleink #endif
1797684d5e0Skleink 
1807684d5e0Skleink #ifdef __cplusplus
1817684d5e0Skleink }
1827684d5e0Skleink #endif
1837684d5e0Skleink #endif /* GDTOA_H_INCLUDED */
184