Source code of Windows XP (NT5)
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.

84 lines
2.8 KiB

  1. /***
  2. *atof.c - convert char string to floating point number
  3. *
  4. * Copyright (c) 1985-2001, 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. * 04-06-93 SKS Replace _CRTAPI* with _cdecl
  29. * 09-06-94 CFW Replace MTHREAD with _MT.
  30. * 12-15-98 GJF Changes for 64-bit size_t.
  31. *
  32. *******************************************************************************/
  33. #include <stdlib.h>
  34. #include <math.h>
  35. #include <cruntime.h>
  36. #include <fltintrn.h>
  37. #include <string.h>
  38. #include <ctype.h>
  39. /***
  40. *double atof(nptr) - convert string to floating point number
  41. *
  42. *Purpose:
  43. * atof recognizes an optional string of whitespace, then
  44. * an optional sign, then a string of digits optionally
  45. * containing a decimal point, then an optional e or E followed
  46. * by an optionally signed integer, and converts all this to
  47. * to a floating point number. The first unrecognized
  48. * character ends the string.
  49. *
  50. *Entry:
  51. * nptr - pointer to string to convert
  52. *
  53. *Exit:
  54. * returns floating point value of character representation
  55. *
  56. *Exceptions:
  57. *
  58. *******************************************************************************/
  59. double __cdecl atof(
  60. REG1 const char *nptr
  61. )
  62. {
  63. #ifdef _MT
  64. struct _flt fltstruct; /* temporary structure */
  65. #endif
  66. /* scan past leading space/tab characters */
  67. while ( isspace((int)(unsigned char)*nptr) )
  68. nptr++;
  69. /* let _fltin routine do the rest of the work */
  70. #ifdef _MT
  71. return( *(double *)&(_fltin2( &fltstruct, nptr, (int)strlen(nptr), 0, 0 )->
  72. dval) );
  73. #else
  74. return( *(double *)&(_fltin( nptr, (int)strlen(nptr), 0, 0 )->dval) );
  75. #endif
  76. }