MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / Atof

Function Atof

include/LightGBM/utils/common.h:180–270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

178}
179
180inline static const char* Atof(const char* p, double* out) {
181 int frac;
182 double sign, value, scale;
183 *out = NAN;
184 // Skip leading white space, if any.
185 while (*p == ' ') {
186 ++p;
187 }
188 // Get sign, if any.
189 sign = 1.0;
190 if (*p == '-') {
191 sign = -1.0;
192 ++p;
193 } else if (*p == '+') {
194 ++p;
195 }
196
197 // is a number
198 if ((*p >= '0' && *p <= '9') || *p == '.' || *p == 'e' || *p == 'E') {
199 // Get digits before decimal point or exponent, if any.
200 for (value = 0.0; *p >= '0' && *p <= '9'; ++p) {
201 value = value * 10.0 + (*p - '0');
202 }
203
204 // Get digits after decimal point, if any.
205 if (*p == '.') {
206 double right = 0.0;
207 int nn = 0;
208 ++p;
209 while (*p >= '0' && *p <= '9') {
210 right = (*p - '0') + right * 10.0;
211 ++nn;
212 ++p;
213 }
214 value += right / Pow(10.0, nn);
215 }
216
217 // Handle exponent, if any.
218 frac = 0;
219 scale = 1.0;
220 if ((*p == 'e') || (*p == 'E')) {
221 uint32_t expon;
222 // Get sign of exponent, if any.
223 ++p;
224 if (*p == '-') {
225 frac = 1;
226 ++p;
227 } else if (*p == '+') {
228 ++p;
229 }
230 // Get digits of exponent, if any.
231 for (expon = 0; *p >= '0' && *p <= '9'; ++p) {
232 expon = expon * 10 + (*p - '0');
233 }
234 if (expon > 308) expon = 308;
235 // Calculate scaling factor.
236 while (expon >= 50) { scale *= 1E50; expon -= 50; }
237 while (expon >= 8) { scale *= 1E8; expon -= 8; }

Callers 10

AtofAndCheckFunction · 0.70
operator()Method · 0.70
BinaryLoglossMethod · 0.50
MulticlassOVAMethod · 0.50
LoadWeightsMethod · 0.50
LoadInitialScoreMethod · 0.50
ParseOneLineMethod · 0.50
ParseOneLineMethod · 0.50
ParseOneLineMethod · 0.50
TreeMethod · 0.50

Calls 4

transformFunction · 0.85
PowFunction · 0.70
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected