mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
printf: Support printing negative values with %f or %g.
This commit is contained in:
parent
4080221547
commit
9149a519f5
Notes:
sideshowbarker
2024-07-19 13:32:57 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/9149a519f5f
|
@ -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…
Reference in a new issue