Leaked source code of windows server 2003
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.

64 lines
1.7 KiB

  1. /***
  2. *fltinf.c - Encode interface for FORTRAN
  3. *
  4. * Copyright (c) 1992-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * FORTRAN interface for decimal to binary (input) conversion
  8. *
  9. *Revision History:
  10. * 06-22-92 GDP Modified version of cfin.c for FORTRAN support
  11. * 04-06-93 SKS Replace _CALLTYPE* with __cdecl
  12. * 10-06-99 PML Copy a DOUBLE, not double, to avoid exceptions
  13. *
  14. *******************************************************************************/
  15. #include <string.h>
  16. #include <cv.h>
  17. static struct _flt ret;
  18. static FLT flt = &ret;
  19. /* Error codes set by this routine */
  20. #define CFIN_NODIGITS 512
  21. #define CFIN_OVERFLOW 128
  22. #define CFIN_UNDERFLOW 256
  23. #define CFIN_INVALID 64
  24. FLT __cdecl _fltinf(const char *str, int len, int scale, int decpt)
  25. {
  26. _LDBL12 ld12;
  27. DOUBLE x;
  28. const char *EndPtr;
  29. unsigned flags;
  30. int retflags = 0;
  31. flags = __strgtold12(&ld12, &EndPtr, str, 0, scale, decpt, 1);
  32. if (flags & SLD_NODIGITS) {
  33. retflags |= CFIN_NODIGITS;
  34. *(u_long *)&x = 0;
  35. *((u_long *)&x+1) = 0;
  36. }
  37. else {
  38. INTRNCVT_STATUS intrncvt;
  39. intrncvt = _ld12tod(&ld12, &x);
  40. if (flags & SLD_OVERFLOW ||
  41. intrncvt == INTRNCVT_OVERFLOW) {
  42. retflags |= CFIN_OVERFLOW;
  43. }
  44. if (flags & SLD_UNDERFLOW ||
  45. intrncvt == INTRNCVT_UNDERFLOW) {
  46. retflags |= CFIN_UNDERFLOW;
  47. }
  48. }
  49. flt->nbytes = (int)(EndPtr - str);
  50. if (len != flt->nbytes)
  51. retflags |= CFIN_INVALID;
  52. *(DOUBLE *)&flt->dval = *(DOUBLE *)&x;
  53. flt->flags = retflags;
  54. return flt;
  55. }