home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 8.ddi / IOSTRSR1.ZIP / ISTEFLT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.5 KB  |  53 lines

  1. /*[]------------------------------------------------------------[]*/
  2. /*|                                                              |*/
  3. /*|     isteflt.cpp                                              |*/
  4. /*|                                                              |*/
  5. /*|     Class istream                                            |*/
  6. /*|          istream& istream::operator>> ( float& )             |*/
  7. /*|                                                              |*/
  8. /*[]------------------------------------------------------------[]*/
  9.  
  10. /*
  11.  *      C/C++ Run Time Library - Version 5.0
  12.  *
  13.  *      Copyright (c) 1990, 1992 by Borland International
  14.  *      All Rights Reserved.
  15.  *
  16.  */
  17.  
  18. #include <ioconfig.h>
  19. #include <iostream.h>
  20. #include <float.h>  // for characteristics of floating types
  21. #include <errno.h>  // for reporting range errors
  22.  
  23.  
  24.  
  25. /*
  26.  * We assume that extracting a long double and casting to float is not
  27.  * significantly more expensive than working only with floats.
  28.  */
  29. istream _FAR & istream::operator>> (float _FAR & f)
  30. {
  31.     long double x;
  32.  
  33.     *this >> x;     // extract the value
  34.     if( ! fail() )
  35.         {    // value returned only if no failure
  36.         if( x < -FLT_MAX )
  37.             {
  38.             errno = ERANGE;
  39.             f = -FLT_MAX;
  40.             }
  41.         else if( FLT_MAX < x )
  42.             {
  43.             errno = ERANGE;
  44.             f = FLT_MAX;
  45.             }
  46.         else
  47.             f = float(x);
  48.         }
  49.     return *this;
  50. }
  51.  
  52.  
  53.