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.

62 lines
1.6 KiB

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