MCPcopy Create free account
hub / github.com/baldurk/renderdoc / PrintFloat

Function PrintFloat

renderdoc/strings/utf8printf.cpp:545–1185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

543}
544
545void PrintFloat(double argd, FormatterParams &formatter, bool e, bool f, bool g, bool a,
546 bool uppercaseDigits, char *&output, size_t &actualsize, char *end)
547{
548 // extract the pieces out of the double
549 uint64_t *arg64 = (uint64_t *)&argd;
550 bool signbit = (*arg64 & 0x8000000000000000) ? true : false;
551 uint64_t rawexp = (*arg64 & 0x7ff0000000000000) >> 52;
552 int exponent = int(rawexp) - 1023;
553 uint64_t mantissa = (*arg64 & 0x000fffffffffffff);
554
555 char prepend = '\0';
556
557 if(signbit)
558 prepend = '-';
559 else if(formatter.Flags & PrependPos)
560 prepend = '+';
561 else if(formatter.Flags & PrependSpace)
562 prepend = ' ';
563
564 // special-case handling of printing 0
565 if(rawexp == 0 && mantissa == 0)
566 {
567 PrintFloat0(e, f, a, uppercaseDigits, formatter, prepend, output, actualsize, end);
568 }
569 // handle 'special' values, inf and nan
570 else if(rawexp == 0x7ff)
571 {
572 if(mantissa == 0)
573 {
574 if(signbit)
575 appendstring(output, actualsize, end, uppercaseDigits ? "-INF" : "-inf");
576 else
577 appendstring(output, actualsize, end, uppercaseDigits ? "+INF" : "+inf");
578 }
579 else
580 {
581 appendstring(output, actualsize, end, uppercaseDigits ? "NAN" : "nan");
582 }
583 }
584 else if(a)
585 {
586 char digits[18] = {0};
587 int ndigits = 0;
588
589 for(int d = 12; mantissa && d >= 0; d--)
590 {
591 const uint64_t mask = 0xfULL << (d * 4);
592 const uint64_t digit = (mantissa & mask) >> (d * 4);
593
594 char c = char('0' + digit);
595 if(digit >= 10)
596 c = char((uppercaseDigits ? 'A' : 'a') + digit - 10);
597
598 digits[ndigits++] = c;
599
600 mantissa &= ~mask;
601 }
602

Callers 1

formatargumentFunction · 0.85

Calls 6

PrintFloat0Function · 0.85
appendstringFunction · 0.85
addcharFunction · 0.85
addcharsFunction · 0.85
grisu2Function · 0.85
RDCMAXFunction · 0.85

Tested by

no test coverage detected