printf: Support printing negative values with %f or %g.

This commit is contained in:
Andreas Kling 2019-06-18 14:47:52 +02:00
parent 4080221547
commit 9149a519f5
Notes: sideshowbarker 2024-07-19 13:32:57 +09:00

View file

@ -106,6 +106,16 @@ template<typename PutChFunc>
return fieldWidth;
}
template<typename PutChFunc>
[[gnu::always_inline]] inline int print_signed_qword(PutChFunc putch, char*& bufptr, signed_qword number, bool leftPad, bool zeroPad, dword fieldWidth)
{
if (number < 0) {
putch(bufptr, '-');
return print_qword(putch, bufptr, 0 - number, leftPad, zeroPad, fieldWidth) + 1;
}
return print_qword(putch, bufptr, number, leftPad, zeroPad, fieldWidth);
}
template<typename PutChFunc>
[[gnu::always_inline]] inline int print_octal_number(PutChFunc putch, char*& bufptr, dword number, bool leftPad, bool zeroPad, dword fieldWidth)
{
@ -246,7 +256,7 @@ template<typename PutChFunc>
case 'g':
case 'f':
// FIXME: Print as float!
ret += print_number(putch, bufptr, (int)va_arg(ap, double), leftPad, zeroPad, fieldWidth);
ret += print_signed_qword(putch, bufptr, (qword)va_arg(ap, double), leftPad, zeroPad, fieldWidth);
break;
#endif