home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / istrflt.cpp < prev    next >
C/C++ Source or Header  |  1998-06-17  |  1KB  |  49 lines

  1. /***
  2. * istrflt.cpp - definitions for istream operator>>(float) member function
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Definitions of operator>>(float) member function for istream class.
  8. *       [AT&T C++]
  9. *
  10. *******************************************************************************/
  11.  
  12. #include <cruntime.h>
  13. #include <internal.h>
  14. #include <stdlib.h>
  15. #include <float.h>
  16. #include <iostream.h>
  17. #pragma hdrstop
  18.  
  19. #pragma check_stack(on)         // large buffer(s)
  20.  
  21. #define MAXFLTSIZ       20
  22.  
  23. istream& istream::operator>>(float& n)
  24. {
  25. _WINSTATIC char ibuffer[MAXFLTSIZ];
  26.     double d;
  27.     char ** endptr = (char**)NULL;
  28.     if (ipfx(0))
  29.         {
  30.         if (getdouble(ibuffer, MAXFLTSIZ)>0)
  31.             {
  32.             d = strtod(ibuffer, endptr);
  33.  
  34.             if (d > FLT_MAX)
  35.                 n = FLT_MAX;
  36.             else if (d < -FLT_MAX)
  37.                 n =  -FLT_MAX;
  38.             else if ((d>0) && (d< FLT_MIN))
  39.                 n = FLT_MIN;
  40.             else if ((d<0) && (d> -FLT_MIN))
  41.                 n = - FLT_MIN;
  42.             else
  43.                 n = (float) d;
  44.             }
  45.         isfx();
  46.         }
  47. return *this;
  48. }
  49.