Windows NT 4.0 source code leak
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.

81 lines
2.3 KiB

4 years ago
  1. /***
  2. *atof.c - convert char string to floating point number
  3. *
  4. * Copyright (c) 1985-1992, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Converts a character string into a floating point number.
  8. *
  9. *Revision History:
  10. * 09-09-87 RKW written
  11. * 04-13-87 JCR added const to declaration
  12. * 11-09-87 BCM different interface under ifdef MTHREAD
  13. * 12-11-87 JCR Added "_LOAD_DS" to declaration
  14. * 05-24-88 PHG Merged DLL and normal versions
  15. * 08-18-88 PHG now calls isspace to process all kinds of whitespce
  16. * 10-04-88 JCR 386: Removed 'far' keyword
  17. * 11-20-89 JCR atof() is always _cdecl in 386 (not pascal)
  18. * 03-05-90 GJF Fixed calling type, added #include <cruntime.h>,
  19. * removed #include <register.h>, removed some redundant
  20. * prototypes, removed some leftover 16-bit support and
  21. * fixed the copyright. Also, cleaned up the formatting
  22. * a bit.
  23. * 07-20-90 SBM Compiles cleanly with -W3 (added/removed appropriate
  24. * #includes)
  25. * 08-01-90 SBM Renamed <struct.h> to <fltintrn.h>
  26. * 09-27-90 GJF New-style function declarator.
  27. * 10-21-92 GJF Made char-to-int conversion unsigned.
  28. *
  29. *******************************************************************************/
  30. #include <stdlib.h>
  31. #include <math.h>
  32. #include <cruntime.h>
  33. #include <fltintrn.h>
  34. #include <string.h>
  35. #include <ctype.h>
  36. /***
  37. *double atof(nptr) - convert string to floating point number
  38. *
  39. *Purpose:
  40. * atof recognizes an optional string of whitespace, then
  41. * an optional sign, then a string of digits optionally
  42. * containing a decimal point, then an optional e or E followed
  43. * by an optionally signed integer, and converts all this to
  44. * to a floating point number. The first unrecognized
  45. * character ends the string.
  46. *
  47. *Entry:
  48. * nptr - pointer to string to convert
  49. *
  50. *Exit:
  51. * returns floating point value of character representation
  52. *
  53. *Exceptions:
  54. *
  55. *******************************************************************************/
  56. double _CRTAPI1 atof(
  57. REG1 const char *nptr
  58. )
  59. {
  60. #ifdef MTHREAD
  61. struct _flt fltstruct; /* temporary structure */
  62. #endif
  63. /* scan past leading space/tab characters */
  64. while ( isspace((int)(unsigned char)*nptr) )
  65. nptr++;
  66. /* let _fltin routine do the rest of the work */
  67. #ifdef MTHREAD
  68. return( *(double *)&(_fltin2( &fltstruct, nptr, strlen(nptr), 0, 0 )->
  69. dval) );
  70. #else
  71. return( *(double *)&(_fltin( nptr, strlen(nptr), 0, 0 )->dval) );
  72. #endif
  73. }