MCPcopy Create free account
hub / github.com/Panzerschrek/Chasm-Reverse / StrToFloat

Function StrToFloat

PanzerChasm/settings.cpp:36–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36static bool StrToFloat( const char* str, float* f )
37{
38 float sign = 1.0f;
39 if( str[0] == '-' )
40 {
41 sign = -1.0f;
42 str++;
43 }
44
45 float v = 0;
46 while( *str != 0 )
47 {
48 if( str[0] == ',' || str[0] == '.' )
49 {
50 str++;
51 break;
52 }
53 if( str[0] < '0' || str[0] > '9' )
54 return false;
55 v*= 10.0f;
56 v+= float(str[0] - '0');
57 str++;
58 }
59 float m = 0.1f;
60 while( *str != 0 )
61 {
62 if( str[0] < '0' || str[0] > '9' )
63 return false;
64
65 v+= float(str[0] - '0') * m;
66 m*= 0.1f;
67 str++;
68 }
69
70 *f= v * sign;
71 return true;
72}
73
74std::string FloatToStr( const float f )
75{

Callers 3

IsNumberMethod · 0.85
GetFloatMethod · 0.85
GetOrSetFloatMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected