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.

74 lines
1.9 KiB

  1. /***
  2. *cfin.c - Encode interface for C
  3. *
  4. * Copyright (c) 1991-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *
  8. *Revision History:
  9. * 07-20-91 GDP Ported to C from assembly
  10. * 04-30-92 GDP use __strgtold12 and _ld12tod
  11. * 06-22-92 GDP use new __strgtold12 interface
  12. * 04-06-93 SKS Replace _CALLTYPE* with __cdecl
  13. * 09-06-94 CFW Replace MTHREAD with _MT.
  14. * 10-06-99 PML Copy a DOUBLE, not double, to avoid exceptions
  15. *
  16. *******************************************************************************/
  17. #include <string.h>
  18. #include <cv.h>
  19. #ifndef _MT
  20. static struct _flt ret;
  21. static FLT flt = &ret;
  22. #endif
  23. /* The only three conditions that this routine detects */
  24. #define CFIN_NODIGITS 512
  25. #define CFIN_OVERFLOW 128
  26. #define CFIN_UNDERFLOW 256
  27. /* This version ignores the last two arguments (radix and scale)
  28. * Input string should be null terminated
  29. * len is also ignored
  30. */
  31. #ifdef _MT
  32. FLT __cdecl _fltin2(FLT flt, const char *str, int len_ignore, int scale_ignore, int radix_ignore)
  33. #else
  34. FLT __cdecl _fltin(const char *str, int len_ignore, int scale_ignore, int radix_ignore)
  35. #endif
  36. {
  37. _LDBL12 ld12;
  38. DOUBLE x;
  39. const char *EndPtr;
  40. unsigned flags;
  41. int retflags = 0;
  42. flags = __strgtold12(&ld12, &EndPtr, str, 0, 0, 0, 0);
  43. if (flags & SLD_NODIGITS) {
  44. retflags |= CFIN_NODIGITS;
  45. *(u_long *)&x = 0;
  46. *((u_long *)&x+1) = 0;
  47. }
  48. else {
  49. INTRNCVT_STATUS intrncvt;
  50. intrncvt = _ld12tod(&ld12, &x);
  51. if (flags & SLD_OVERFLOW ||
  52. intrncvt == INTRNCVT_OVERFLOW) {
  53. retflags |= CFIN_OVERFLOW;
  54. }
  55. if (flags & SLD_UNDERFLOW ||
  56. intrncvt == INTRNCVT_UNDERFLOW) {
  57. retflags |= CFIN_UNDERFLOW;
  58. }
  59. }
  60. flt->flags = retflags;
  61. flt->nbytes = (int)(EndPtr - str);
  62. *(DOUBLE *)&flt->dval = *(DOUBLE *)&x;
  63. return flt;
  64. }