MCPcopy Create free account
hub / github.com/OpenDriveLab/OpenLane / string2double

Function string2double

eval/CIPO_evaluation/common/gason.cpp:95–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93}
94
95static double string2double(char *s, char **endptr) {
96 char ch = *s;
97 if (ch == '-')
98 ++s;
99
100 double result = 0;
101 while (isdigit(*s))
102 result = (result * 10) + (*s++ - '0');
103
104 if (*s == '.') {
105 ++s;
106
107 double fraction = 1;
108 while (isdigit(*s)) {
109 fraction *= 0.1;
110 result += (*s++ - '0') * fraction;
111 }
112 }
113
114 if (*s == 'e' || *s == 'E') {
115 ++s;
116
117 double base = 10;
118 if (*s == '+')
119 ++s;
120 else if (*s == '-') {
121 ++s;
122 base = 0.1;
123 }
124
125 unsigned int exponent = 0;
126 while (isdigit(*s))
127 exponent = (exponent * 10) + (*s++ - '0');
128
129 double power = 1;
130 for (; exponent; exponent >>= 1, base *= base)
131 if (exponent & 1)
132 power *= base;
133
134 result *= power;
135 }
136
137 *endptr = s;
138 return ch == '-' ? -result : result;
139}
140
141static inline JsonNode *insertAfter(JsonNode *tail, JsonNode *node) {
142 if (!tail)

Callers 1

jsonParseFunction · 0.85

Calls 1

isdigitFunction · 0.85

Tested by

no test coverage detected