Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

453 lines
13 KiB

  1. /***
  2. *cv.h - definitions for floating point conversion
  3. *
  4. * Copyright (c) 1991-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * define types, macros, and constants used in floating point
  8. * conversion routines
  9. *
  10. *Revision History:
  11. * 07-17-91 GDP initial version
  12. * 09-21-91 GDP restructured 'ifdef' directives
  13. * 10-29-91 GDP MIPS port: new defs for ALIGN and DOUBLE
  14. * 03-03-92 GDP removed os2 16-bit stuff
  15. * 04-30-92 GDP support intrncvt.c --cleanup and reorganize
  16. * 05-13-92 XY fixed B_END macros
  17. * 06-16-92 GDP merged changes from \\orville and \\vangogh trees
  18. * 09-05-92 GDP included fltintrn.h, new calling convention macros
  19. * 04-06-93 SKS Replace _CALLTYPE* with __cdecl
  20. * 07-16-93 SRW ALPHA Merge
  21. * 11-17-93 GJF Merged in NT version. Replaced _ALPHA_ with _M_ALPHA,
  22. * MIPS with _M_MRX000, MTHREAD with _MT, and deleted
  23. * M68K stuff.
  24. * 10-02-94 BWT PPC merge
  25. * 02-06-95 JWM Mac merge
  26. * 10-07-97 RDL Added IA64.
  27. * 05-05-99 RDL Added _M_IA64 to #if def's for alignment.
  28. * 05-13-99 PML Remove _CRTAPI1
  29. * 05-17-99 PML Remove all Macintosh support.
  30. *
  31. *******************************************************************************/
  32. #ifndef _INC_CV
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. #include <cruntime.h>
  37. /* Define __cdecl for non-Microsoft compilers */
  38. #if ( !defined(_MSC_VER) && !defined(__cdecl) )
  39. #define __cdecl
  40. #endif
  41. #include <fltintrn.h>
  42. /* define little endian or big endian memory */
  43. #if defined(_M_IX86) || defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_PPC) || defined(_M_IA64) || defined(_M_AMD64)
  44. #define L_END
  45. #endif
  46. typedef unsigned char u_char; /* should have 1 byte */
  47. typedef char s_char; /* should have 1 byte */
  48. typedef unsigned short u_short; /* should have 2 bytes */
  49. typedef signed short s_short; /* should have 2 bytes */
  50. typedef unsigned int u_long; /* sholuld have 4 bytes */
  51. typedef int s_long; /* sholuld have 4 bytes */
  52. /* calling conventions */
  53. #define _CALLTYPE5
  54. /*
  55. * defining _LDSUPPORT enables using long double computations
  56. * for string conversion. We do not do this even for i386,
  57. * since we want to avoid using floating point code that
  58. * may generate IEEE exceptions.
  59. *
  60. * Currently our string conversion routines do not conform
  61. * to the special requirements of the IEEE standard for
  62. * floating point conversions
  63. */
  64. #ifndef _LDSUPPORT
  65. #pragma pack(4)
  66. typedef struct {
  67. u_char ld[10];
  68. } _LDOUBLE;
  69. #pragma pack()
  70. #define PTR_LD(x) ((u_char *)(&(x)->ld))
  71. #else
  72. typedef long double _LDOUBLE;
  73. #define PTR_LD(x) ((u_char *)(x))
  74. #endif
  75. #pragma pack(4)
  76. typedef struct {
  77. u_char ld12[12];
  78. } _LDBL12;
  79. #pragma pack()
  80. typedef struct {
  81. float f;
  82. } FLOAT;
  83. /*
  84. * return values for internal conversion routines
  85. * (12-byte to long double, double, or float)
  86. */
  87. typedef enum {
  88. INTRNCVT_OK,
  89. INTRNCVT_OVERFLOW,
  90. INTRNCVT_UNDERFLOW
  91. } INTRNCVT_STATUS;
  92. /*
  93. * return values for strgtold12 routine
  94. */
  95. #define SLD_UNDERFLOW 1
  96. #define SLD_OVERFLOW 2
  97. #define SLD_NODIGITS 4
  98. #define MAX_MAN_DIGITS 21
  99. /* specifies '%f' format */
  100. #define SO_FFORMAT 1
  101. typedef struct _FloatOutStruct {
  102. short exp;
  103. char sign;
  104. char ManLen;
  105. char man[MAX_MAN_DIGITS+1];
  106. } FOS;
  107. #define PTR_12(x) ((u_char *)(&(x)->ld12))
  108. #define MAX_USHORT ((u_short)0xffff)
  109. #define MSB_USHORT ((u_short)0x8000)
  110. #define MAX_ULONG ((u_long)0xffffffff)
  111. #define MSB_ULONG ((u_long)0x80000000)
  112. #define TMAX10 5200 /* maximum temporary decimal exponent */
  113. #define TMIN10 -5200 /* minimum temporary decimal exponent */
  114. #define LD_MAX_EXP_LEN 4 /* maximum number of decimal exponent digits */
  115. #define LD_MAX_MAN_LEN 24 /* maximum length of mantissa (decimal)*/
  116. #define LD_MAX_MAN_LEN1 25 /* MAX_MAN_LEN+1 */
  117. #define LD_BIAS 0x3fff /* exponent bias for long double */
  118. #define LD_BIASM1 0x3ffe /* LD_BIAS - 1 */
  119. #define LD_MAXEXP 0x7fff /* maximum biased exponent */
  120. #define D_BIAS 0x3ff /* exponent bias for double */
  121. #define D_BIASM1 0x3fe /* D_BIAS - 1 */
  122. #define D_MAXEXP 0x7ff /* maximum biased exponent */
  123. /*
  124. * end of definitions from crt32\h\fltintrn.h
  125. */
  126. /* Recognizing special patterns in the mantissa field */
  127. #define _EXP_SP 0x7fff
  128. #define NAN_BIT (1<<30)
  129. #define _IS_MAN_INF(signbit, manhi, manlo) \
  130. ( (manhi)==MSB_ULONG && (manlo)==0x0 )
  131. /* i386 and Alpha use same NaN format */
  132. #if defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC) || defined(_M_IA64) || defined(_M_AMD64)
  133. #define _IS_MAN_IND(signbit, manhi, manlo) \
  134. ((signbit) && (manhi)==0xc0000000 && (manlo)==0)
  135. #define _IS_MAN_QNAN(signbit, manhi, manlo) \
  136. ( (manhi)&NAN_BIT )
  137. #define _IS_MAN_SNAN(signbit, manhi, manlo) \
  138. (!( _IS_MAN_INF(signbit, manhi, manlo) || \
  139. _IS_MAN_QNAN(signbit, manhi, manlo) ))
  140. #elif defined(_M_MRX000)
  141. #define _IS_MAN_IND(signbit, manhi, manlo) \
  142. (!(signbit) && (manhi)==0xbfffffff && (manlo)==0xfffff800)
  143. #define _IS_MAN_SNAN(signbit, manhi, manlo) \
  144. ( (manhi)&NAN_BIT )
  145. #define _IS_MAN_QNAN(signbit, manhi, manlo) \
  146. (!( _IS_MAN_INF(signbit, manhi, manlo) || \
  147. _IS_MAN_SNAN(signbit, manhi, manlo) ))
  148. #endif
  149. #if defined (L_END) && !( defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_PPC) || defined(_M_IA64) )
  150. /* "little endian" memory */
  151. /* Note: MIPS and Alpha have alignment requirements and have different
  152. * macros */
  153. /*
  154. * Manipulation of a 12-byte long double number (an ordinary
  155. * 10-byte long double plus two extra bytes of mantissa).
  156. */
  157. /*
  158. * byte layout:
  159. *
  160. * +-----+--------+--------+-------+
  161. * |XT(2)|MANLO(4)|MANHI(4)|EXP(2) |
  162. * +-----+--------+--------+-------+
  163. * |<-UL_LO->|<-UL_MED->|<-UL_HI ->|
  164. * (4) (4) (4)
  165. */
  166. /* a pointer to the exponent/sign portion */
  167. #define U_EXP_12(p) ((u_short *)(PTR_12(p)+10))
  168. /* a pointer to the 4 hi-order bytes of the mantissa */
  169. #define UL_MANHI_12(p) ((u_long *)(PTR_12(p)+6))
  170. /* a pointer to the 4 lo-order bytes of the ordinary (8-byte) mantissa */
  171. #define UL_MANLO_12(p) ((u_long *)(PTR_12(p)+2))
  172. /* a pointer to the 2 extra bytes of the mantissa */
  173. #define U_XT_12(p) ((u_short *)PTR_12(p))
  174. /* a pointer to the 4 lo-order bytes of the extended (10-byte) mantissa */
  175. #define UL_LO_12(p) ((u_long *)PTR_12(p))
  176. /* a pointer to the 4 mid-order bytes of the extended (10-byte) mantissa */
  177. #define UL_MED_12(p) ((u_long *)(PTR_12(p)+4))
  178. /* a pointer to the 4 hi-order bytes of the extended long double */
  179. #define UL_HI_12(p) ((u_long *)(PTR_12(p)+8))
  180. /* a pointer to the byte of order i (LSB=0, MSB=9)*/
  181. #define UCHAR_12(p,i) ((u_char *)PTR_12(p)+(i))
  182. /* a pointer to a u_short with offset i */
  183. #define USHORT_12(p,i) ((u_short *)((u_char *)PTR_12(p)+(i)))
  184. /* a pointer to a u_long with offset i */
  185. #define ULONG_12(p,i) ((u_long *)((u_char *)PTR_12(p)+(i)))
  186. /* a pointer to the 10 MSBytes of a 12-byte long double */
  187. #define TEN_BYTE_PART(p) ((u_char *)PTR_12(p)+2)
  188. /*
  189. * Manipulation of a 10-byte long double number
  190. */
  191. #define U_EXP_LD(p) ((u_short *)(PTR_LD(p)+8))
  192. #define UL_MANHI_LD(p) ((u_long *)(PTR_LD(p)+4))
  193. #define UL_MANLO_LD(p) ((u_long *)PTR_LD(p))
  194. /*
  195. * Manipulation of a 64bit IEEE double
  196. */
  197. #define U_SHORT4_D(p) ((u_short *)(p) + 3)
  198. #define UL_HI_D(p) ((u_long *)(p) + 1)
  199. #define UL_LO_D(p) ((u_long *)(p))
  200. #endif
  201. /* big endian */
  202. #if defined (B_END)
  203. /*
  204. * byte layout:
  205. *
  206. * +------+-------+---------+------+
  207. * |EXP(2)|MANHI(4)|MANLO(4)|XT(2) |
  208. * +------+-------+---------+------+
  209. * |<-UL_HI->|<-UL_MED->|<-UL_LO ->|
  210. * (4) (4) (4)
  211. */
  212. #define U_EXP_12(p) ((u_short *)PTR_12(p))
  213. #define UL_MANHI_12(p) ((u_long *)(PTR_12(p)+2))
  214. #define UL_MANLO_12(p) ((u_long *)(PTR_12(p)+6))
  215. #define U_XT_12(p) ((u_short *)(PTR_12(p)+10))
  216. #define UL_LO_12(p) ((u_long *)(PTR_12(p)+8))
  217. #define UL_MED_12(p) ((u_long *)(PTR_12(p)+4))
  218. #define UL_HI_12(p) ((u_long *)PTR_12(p))
  219. #define UCHAR_12(p,i) ((u_char *)PTR_12(p)+(11-(i)))
  220. #define USHORT_12(p,i) ((u_short *)((u_char *)PTR_12(p)+10-(i)))
  221. #define ULONG_12(p,i) ((u_long *)((u_char *)PTR_12(p)+8-(i)))
  222. #define TEN_BYTE_PART(p) (u_char *)PTR_12(p)
  223. #define U_EXP_LD(p) ((u_short *)PTR_LD(p))
  224. #define UL_MANHI_LD(p) ((u_long *)(PTR_LD(p)+2))
  225. #define UL_MANLO_LD(p) ((u_long *)(PTR_LD(p)+6))
  226. /*
  227. * Manipulation of a 64bit IEEE double
  228. */
  229. #define U_SHORT4_D(p) ((u_short *)(p))
  230. #define UL_HI_D(p) ((u_long *)(p))
  231. #define UL_LO_D(p) ((u_long *)(p) + 1)
  232. #endif
  233. #if defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_PPC) || defined(_M_IA64)
  234. #define ALIGN(x) ( (unsigned long __unaligned *) (x))
  235. #define U_EXP_12(p) ((u_short *)(PTR_12(p)+10))
  236. #define UL_MANHI_12(p) ((u_long __unaligned *) (PTR_12(p)+6) )
  237. #define UL_MANLO_12(p) ((u_long __unaligned *) (PTR_12(p)+2) )
  238. #define U_XT_12(p) ((u_short *)PTR_12(p))
  239. #define UL_LO_12(p) ((u_long *)PTR_12(p))
  240. #define UL_MED_12(p) ((u_long *)(PTR_12(p)+4))
  241. #define UL_HI_12(p) ((u_long *)(PTR_12(p)+8))
  242. /* the following 3 macros do not take care of proper alignment */
  243. #define UCHAR_12(p,i) ((u_char *)PTR_12(p)+(i))
  244. #define USHORT_12(p,i) ((u_short *)((u_char *)PTR_12(p)+(i)))
  245. #define ULONG_12(p,i) ((u_long *) ((u_char *)PTR_12(p)+(i) ))
  246. #define TEN_BYTE_PART(p) ((u_char *)PTR_12(p)+2)
  247. /*
  248. * Manipulation of a 10-byte long double number
  249. */
  250. #define U_EXP_LD(p) ((u_short *)(PTR_LD(p)+8))
  251. #define UL_MANHI_LD(p) ((u_long *) (PTR_LD(p)+4) )
  252. #define UL_MANLO_LD(p) ((u_long *) PTR_LD(p) )
  253. /*
  254. * Manipulation of a 64bit IEEE double
  255. */
  256. #define U_SHORT4_D(p) ((u_short *)(p) + 3)
  257. #define UL_HI_D(p) ((u_long *)(p) + 1)
  258. #define UL_LO_D(p) ((u_long *)(p))
  259. #endif
  260. #define PUT_INF_12(p,sign) \
  261. *UL_HI_12(p) = (sign)?0xffff8000:0x7fff8000; \
  262. *UL_MED_12(p) = 0; \
  263. *UL_LO_12(p) = 0;
  264. #define PUT_ZERO_12(p) *UL_HI_12(p) = 0; \
  265. *UL_MED_12(p) = 0; \
  266. *UL_LO_12(p) = 0;
  267. #define ISZERO_12(p) ((*UL_HI_12(p)&0x7fffffff) == 0 && \
  268. *UL_MED_12(p) == 0 && \
  269. *UL_LO_12(p) == 0 )
  270. #define PUT_INF_LD(p,sign) \
  271. *U_EXP_LD(p) = (sign)?0xffff:0x7fff; \
  272. *UL_MANHI_LD(p) = 0x8000; \
  273. *UL_MANLO_LD(p) = 0;
  274. #define PUT_ZERO_LD(p) *U_EXP_LD(p) = 0; \
  275. *UL_MANHI_LD(p) = 0; \
  276. *UL_MANLO_LD(p) = 0;
  277. #define ISZERO_LD(p) ((*U_EXP_LD(p)&0x7fff) == 0 && \
  278. *UL_MANHI_LD(p) == 0 && \
  279. *UL_MANLO_LD(p) == 0 )
  280. /*********************************************************
  281. *
  282. * Function Prototypes
  283. *
  284. *********************************************************/
  285. /* from mantold.c */
  286. void _CALLTYPE5 __mtold12(char *manptr, unsigned manlen,_LDBL12 *ld12);
  287. int _CALLTYPE5 __addl(u_long x, u_long y, u_long *sum);
  288. void _CALLTYPE5 __shl_12(_LDBL12 *ld12);
  289. void _CALLTYPE5 __shr_12(_LDBL12 *ld12);
  290. void _CALLTYPE5 __add_12(_LDBL12 *x, _LDBL12 *y);
  291. /* from tenpow.c */
  292. void _CALLTYPE5 __multtenpow12(_LDBL12 *pld12,int pow, unsigned mult12);
  293. void _CALLTYPE5 __ld12mul(_LDBL12 *px, _LDBL12 *py);
  294. /* from strgtold.c */
  295. unsigned int __strgtold12(_LDBL12 *pld12,
  296. const char * *p_end_ptr,
  297. const char * str,
  298. int mult12,
  299. int scale,
  300. int decpt,
  301. int implicit_E);
  302. unsigned _CALLTYPE5 __STRINGTOLD(_LDOUBLE *pld,
  303. const char * *p_end_ptr,
  304. const char *str,
  305. int mult12);
  306. /* from x10fout.c */
  307. /* this is defined as void in convert.h
  308. * After porting the asm files to c, we need a return value for
  309. * i10_output, that used to reside in reg. ax
  310. */
  311. int _CALLTYPE5 $I10_OUTPUT(_LDOUBLE ld, int ndigits,
  312. unsigned output_flags, FOS *fos);
  313. /* for cvt.c and fltused.c */
  314. /* The following functions are #defined as macros in fltintrn.h */
  315. #undef _cfltcvt
  316. #undef _cropzeros
  317. #undef _fassign
  318. #undef _forcdecpt
  319. #undef _positive
  320. void __cdecl _cfltcvt(double *arg, char *buffer,
  321. int format, int precision,
  322. int caps);
  323. void __cdecl _cropzeros(char *buf);
  324. void __cdecl _fassign(int flag, char *argument, char *number);
  325. void __cdecl _forcdecpt(char *buf);
  326. int __cdecl _positive(double *arg);
  327. /* from intrncvt.c */
  328. void _atodbl(DOUBLE *d, char *str);
  329. void _atoldbl(_LDOUBLE *ld, char *str);
  330. void _atoflt(FLOAT *f, char *str);
  331. INTRNCVT_STATUS _ld12tod(_LDBL12 *ifp, DOUBLE *d);
  332. INTRNCVT_STATUS _ld12tof(_LDBL12 *ifp, FLOAT *f);
  333. INTRNCVT_STATUS _ld12told(_LDBL12 *ifp, _LDOUBLE *ld);
  334. #ifdef __cplusplus
  335. }
  336. #endif
  337. #define _INC_CV
  338. #endif /* _INC_CV */