Home | History | Annotate | Line # | Download | only in gdtoa
      1 /* $NetBSD: gdtoa.h,v 1.11 2019/08/01 02:27:43 riastradh 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 __LOCALE_T_DECLARED
     42 typedef struct _locale		*locale_t;
     43 #define __LOCALE_T_DECLARED
     44 #endif
     45 
     46 #ifndef Long
     47 #define Long int32_t
     48 #endif
     49 #ifndef ULong
     50 #define ULong uint32_t
     51 #endif
     52 #ifndef UShort
     53 #define UShort uint16_t
     54 #endif
     55 
     56 #ifndef ANSI
     57 #ifdef KR_headers
     58 #define ANSI(x) ()
     59 #define Void /*nothing*/
     60 #else
     61 #define ANSI(x) x
     62 #define Void void
     63 #endif
     64 #endif /* ANSI */
     65 
     66 #ifndef CONST
     67 #ifdef KR_headers
     68 #define CONST /* blank */
     69 #else
     70 #define CONST const
     71 #endif
     72 #endif /* CONST */
     73 
     74  enum {	/* return values from strtodg */
     75 	STRTOG_Zero	= 0,
     76 	STRTOG_Normal	= 1,
     77 	STRTOG_Denormal	= 2,
     78 	STRTOG_Infinite	= 3,
     79 	STRTOG_NaN	= 4,
     80 	STRTOG_NaNbits	= 5,
     81 	STRTOG_NoNumber	= 6,
     82 	STRTOG_Retmask	= 7,
     83 
     84 	/* The following may be or-ed into one of the above values. */
     85 
     86 	STRTOG_Neg	= 0x08, /* does not affect STRTOG_Inexlo or STRTOG_Inexhi */
     87 	STRTOG_Inexlo	= 0x10,	/* returned result rounded toward zero */
     88 	STRTOG_Inexhi	= 0x20, /* returned result rounded away from zero */
     89 	STRTOG_Inexact	= 0x30,
     90 	STRTOG_Underflow= 0x40,
     91 	STRTOG_Overflow	= 0x80,
     92 	STRTOG_NoMemory = 0x100
     93 	};
     94 
     95  typedef struct
     96 FPI {
     97 	int nbits;
     98 	int emin;
     99 	int emax;
    100 	int rounding;
    101 	int sudden_underflow;
    102 	} FPI;
    103 
    104 enum {	/* FPI.rounding values: same as FLT_ROUNDS */
    105 	FPI_Round_zero = 0,
    106 	FPI_Round_near = 1,
    107 	FPI_Round_up = 2,
    108 	FPI_Round_down = 3
    109 	};
    110 
    111 #ifdef __cplusplus
    112 extern "C" {
    113 #endif
    114 
    115 #define	dtoa		__dtoa
    116 #define	gdtoa		__gdtoa
    117 #define	ldtoa		__ldtoa
    118 #define	hldtoa		__hldtoa
    119 #define	hdtoa		__hdtoa
    120 #define	freedtoa	__freedtoa
    121 #define	strtodg		__strtodg_D2A
    122 #define	strtopQ		__strtopQ_D2A
    123 #define	strtopx		__strtopx_D2A
    124 #define	strtopxL	__strtopxL_D2A
    125 #define	strtord		__strtord_D2A
    126 
    127 extern char* dtoa  ANSI((double d, int mode, int ndigits, int *decpt,
    128 			int *sign, char **rve));
    129 extern char* hdtoa ANSI((double d, const char *xdigs, int ndigits, int *decpt,
    130 			int *sign, char **rve));
    131 extern char* ldtoa ANSI((long double *ld, int mode, int ndigits, int *decpt,
    132 			int *sign, char **rve));
    133 extern char* hldtoa ANSI((long double e, const char *xdigs, int ndigits,
    134 			int *decpt, int *sign, char **rve));
    135 
    136 extern char* gdtoa ANSI((CONST FPI *fpi, int be, ULong *bits, int *kindp,
    137 			int mode, int ndigits, int *decpt, char **rve));
    138 extern void freedtoa ANSI((char*));
    139 extern float  strtof ANSI((CONST char *, char **));
    140 extern double strtod ANSI((CONST char *, char **));
    141 extern int strtodg ANSI((CONST char*, char**, CONST FPI*, Long*, ULong*,
    142                          locale_t));
    143 
    144 extern char*	g_ddfmt  ANSI((char*, double*, int, size_t));
    145 extern char*	g_dfmt   ANSI((char*, double*, int, size_t));
    146 extern char*	g_ffmt   ANSI((char*, float*,  int, size_t));
    147 extern char*	g_Qfmt   ANSI((char*, void*,   int, size_t));
    148 extern char*	g_xfmt   ANSI((char*, void*,   int, size_t));
    149 extern char*	g_xLfmt  ANSI((char*, void*,   int, size_t));
    150 
    151 extern int	strtoId  ANSI((CONST char*, char**, double*, double*));
    152 extern int	strtoIdd ANSI((CONST char*, char**, double*, double*));
    153 extern int	strtoIf  ANSI((CONST char*, char**, float*, float*));
    154 extern int	strtoIQ  ANSI((CONST char*, char**, void*, void*));
    155 extern int	strtoIx  ANSI((CONST char*, char**, void*, void*));
    156 extern int	strtoIxL ANSI((CONST char*, char**, void*, void*));
    157 extern int	strtord  ANSI((CONST char*, char**, int, double*, locale_t));
    158 extern int	strtordd ANSI((CONST char*, char**, int, double*));
    159 extern int	strtorf  ANSI((CONST char*, char**, int, float*));
    160 extern int	strtorQ  ANSI((CONST char*, char**, int, void*));
    161 extern int	strtorx  ANSI((CONST char*, char**, int, void*));
    162 extern int	strtorxL ANSI((CONST char*, char**, int, void*));
    163 #if 1
    164 extern int	strtodI  ANSI((CONST char*, char**, double*));
    165 extern int	strtopd  ANSI((CONST char*, char**, double*));
    166 extern int	strtopdd ANSI((CONST char*, char**, double*));
    167 extern int	strtopf  ANSI((CONST char*, char**, float*));
    168 extern int	strtopQ  ANSI((CONST char*, char**, void*, locale_t));
    169 extern int	strtopx  ANSI((CONST char*, char**, void*, locale_t));
    170 extern int	strtopxL ANSI((CONST char*, char**, void*, locale_t));
    171 #else
    172 #define strtopd(s,se,x) strtord(s,se,1,x)
    173 #define strtopdd(s,se,x) strtordd(s,se,1,x)
    174 #define strtopf(s,se,x) strtorf(s,se,1,x)
    175 #define strtopQ(s,se,x) strtorQ(s,se,1,x)
    176 #define strtopx(s,se,x) strtorx(s,se,1,x)
    177 #define strtopxL(s,se,x) strtorxL(s,se,1,x)
    178 #endif
    179 
    180 #ifdef __cplusplus
    181 }
    182 #endif
    183 #endif /* GDTOA_H_INCLUDED */
    184