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.

66 lines
1.8 KiB

  1. /***
  2. * ostrdbl.cpp - definitions for ostream class operator<<(double) functions
  3. *
  4. * Copyright (c) 1991-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Contains the member function definitions for ostream operator<<(double).
  8. *
  9. *Revision History:
  10. * 09-23-91 KRS Created. Split out from ostream.cxx for granularity.
  11. * 10-24-91 KRS Combine float version with double.
  12. * 06-14-95 CFW Comment cleanup.
  13. *
  14. *******************************************************************************/
  15. #include <cruntime.h>
  16. #include <internal.h>
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <float.h>
  20. #include <iostream.h>
  21. #pragma hdrstop
  22. #pragma check_stack(on) // large buffer(s)
  23. ostream& ostream::operator<<(double f)
  24. {
  25. _WINSTATIC char obuffer[24];
  26. _WINSTATIC char fmt[8];
  27. _WINSTATIC char leader[4];
  28. char * optr = obuffer;
  29. int x = 0;
  30. // x_floatused nonzero indicates called for float, not double
  31. unsigned int curprecision = (x_floatused) ? FLT_DIG : DBL_DIG;
  32. x_floatused = 0; // reset for next call
  33. curprecision = __min((unsigned)x_precision,curprecision);
  34. if (opfx()) {
  35. if (x_flags & ios::showpos)
  36. leader[x++] = '+';
  37. if (x_flags & ios::showpoint)
  38. leader[x++] = '#'; // show decimal and trailing zeros
  39. leader[x] = '\0';
  40. x = sprintf(fmt,"%%%s.%.0ug",leader,curprecision) - 1;
  41. if ((x_flags & ios::floatfield)==ios::fixed)
  42. fmt[x] = 'f';
  43. else
  44. {
  45. if ((x_flags & ios::floatfield)==ios::scientific)
  46. fmt[x] = 'e';
  47. if (x_flags & uppercase)
  48. fmt[x] = (char)toupper(fmt[x]);
  49. }
  50. sprintf(optr,fmt,f);
  51. x = 0;
  52. if (*optr=='+' || *optr=='-')
  53. leader[x++] = *(optr++);
  54. leader[x] = '\0';
  55. writepad(leader,optr);
  56. osfx();
  57. }
  58. return *this;
  59. }