1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:07:45 +00:00

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

View file

@ -106,6 +106,16 @@ template<typename PutChFunc>
return fieldWidth; 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> template<typename PutChFunc>
[[gnu::always_inline]] inline int print_octal_number(PutChFunc putch, char*& bufptr, dword number, bool leftPad, bool zeroPad, dword fieldWidth) [[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 'g':
case 'f': case 'f':
// FIXME: Print as float! // 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; break;
#endif #endif