341 {
342
343
344
347 }
350 }
351
352 if (precision < 0) {
353
354 sstream stream;
356 return stream.str();
357 }
358
359
360
361
364 }
365
366 const bool negative =
value < 0.0f;
367 const float magnitude = negative ? -
value :
value;
368
369
370
371
372
373
374
375
376
377
378 fl::i64 int_part = static_cast<fl::i64>(magnitude);
379 float residue = magnitude - static_cast<float>(int_part);
380 if (residue < 0.0f) {
381 residue = 0.0f;
382 }
383
384 if (precision == 0) {
385 if (residue >= 0.5f) {
386 ++int_part;
387 }
388 sstream stream;
389 if (negative && int_part != 0) {
390 stream << "-";
391 }
392 stream << int_part;
393 return stream.str();
394 }
395
396 fl::i64 multiplier = 1;
397 for (int i = 0; i < precision; ++i) {
398 multiplier *= 10;
399 }
400
401 fl::i64 frac_part =
402 static_cast<fl::i64>(residue * static_cast<float>(multiplier) + 0.5f);
403 if (frac_part >= multiplier) {
404
405 frac_part -= multiplier;
406 ++int_part;
407 }
408
409 sstream stream;
410
411
412 if (negative && (int_part != 0 || frac_part != 0)) {
413 stream << "-";
414 }
415 stream << int_part;
416 stream << ".";
417
418
419
420
421
422
423 fl::i64 temp_multiplier = multiplier / 10;
424 while (temp_multiplier > 0) {
425 const fl::i64 digit = (frac_part / temp_multiplier) % 10;
426 stream << static_cast<char>('0' + static_cast<int>(digit));
427 temp_multiplier /= 10;
428 }
429
430 return stream.str();
431}
constexpr float kFloatDecimalLimit
bool float_is_finite(float value) FL_NO_EXCEPT
fl::string format_float_scientific(float value, int precision) FL_NO_EXCEPT
constexpr int type_rank< T >::value