mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:17:35 +00:00
printf: Support printing negative values with %f or %g.
This commit is contained in:
parent
4080221547
commit
9149a519f5
1 changed files with 11 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue