ReactOS 0.4.16-dev-1025-gd3456f5
atof.cpp
Go to the documentation of this file.
1//
2// atof.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Definitions of the functions that convert strings to floating point numbers.
7// Note that the str- and wcs-prefixed functions are defined elsewhere. The
8// functions defined here are provided for legacy support.
9//
10// The _atoxxx family of functions convert a string into a floating point
11// number and return either zero (success), or _UNDERFLOW or _OVERFLOW.
12//
13#define _ALLOW_OLD_VALIDATE_MACROS
15
16
17
18template <typename FloatingType, typename Character>
20 FloatingType* const result,
21 Character const* const string,
22 _locale_t const locale
23 ) throw()
24{
26
27 _LocaleUpdate locale_update(locale);
29 locale_update.GetLocaleT(),
31 result);
32
33 switch (status)
34 {
35 case SLD_OVERFLOW: return _OVERFLOW;
36 case SLD_UNDERFLOW: return _UNDERFLOW;
37 default: return 0;
38 }
39}
40
41extern "C" int __cdecl _atoflt_l(_CRT_FLOAT* const result, char const* const string, _locale_t const locale)
42{
43 return common_atodbl_l(&result->f, string, locale);
44}
45
46extern "C" int __cdecl _atoflt(_CRT_FLOAT* const result, char const* const string)
47{
48 return common_atodbl_l(&result->f, string, nullptr);
49}
50
51extern "C" int __cdecl _atodbl_l(_CRT_DOUBLE* const result, char* const string, _locale_t const locale)
52{
53 return common_atodbl_l(&result->x, string, locale);
54}
55
56extern "C" int __cdecl _atodbl(_CRT_DOUBLE* const result, char* const string)
57{
58 return common_atodbl_l(&result->x, string, nullptr);
59}
60
61
62
63template <typename Character>
64static double __cdecl common_atof_l(Character const* const string, _locale_t const locale) throw()
65{
66 _VALIDATE_RETURN(string != nullptr, EINVAL, 0.0);
67
68 _LocaleUpdate locale_update(locale);
69
70 double result{};
72 locale_update.GetLocaleT(),
74 &result);
75 return result;
76}
77
78extern "C" double __cdecl _atof_l(char const* const string, _locale_t const locale)
79{
80 return common_atof_l(string, locale);
81}
82
83extern "C" double __cdecl atof(char const* const string)
84{
85 return common_atof_l(string, nullptr);
86}
87
88extern "C" double __cdecl _wtof_l(wchar_t const* const string, _locale_t const locale)
89{
90 return common_atof_l(string, locale);
91}
92
93extern "C" double __cdecl _wtof(wchar_t const* const string)
94{
95 return common_atof_l(string, nullptr);
96}
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
int __cdecl _atoflt(_CRT_FLOAT *const result, char const *const string)
Definition: atof.cpp:46
int __cdecl _atoflt_l(_CRT_FLOAT *const result, char const *const string, _locale_t const locale)
Definition: atof.cpp:41
double __cdecl _wtof(wchar_t const *const string)
Definition: atof.cpp:93
static int __cdecl common_atodbl_l(FloatingType *const result, Character const *const string, _locale_t const locale)
Definition: atof.cpp:19
int __cdecl _atodbl_l(_CRT_DOUBLE *const result, char *const string, _locale_t const locale)
Definition: atof.cpp:51
double __cdecl _atof_l(char const *const string, _locale_t const locale)
Definition: atof.cpp:78
static double __cdecl common_atof_l(Character const *const string, _locale_t const locale)
Definition: atof.cpp:64
int __cdecl _atodbl(_CRT_DOUBLE *const result, char *const string)
Definition: atof.cpp:56
double __cdecl _wtof_l(wchar_t const *const string, _locale_t const locale)
Definition: atof.cpp:88
Definition: _locale.h:75
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
GLuint64EXT * result
Definition: glext.h:11304
#define _DOMAIN
Definition: math.h:39
#define _UNDERFLOW
Definition: math.h:42
#define _OVERFLOW
Definition: math.h:41
c_string_character_source< Character > __cdecl make_c_string_character_source(Character const *const string, EndPointer const end)
SLD_STATUS __cdecl parse_floating_point(_locale_t const locale, CharacterSource source, FloatingType *const result)
Definition: ps.c:97
double atof()