summaryrefslogtreecommitdiff
path: root/AK/PrintfImplementation.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-06-18 14:47:52 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-18 14:47:52 +0200
commit9149a519f5f1bbe0ad821fb1a6a408663fd3741d (patch)
treeb16776ed0f12c3af65645744df02d11de2d89962 /AK/PrintfImplementation.h
parent4080221547223ec06a06b03abfc86a56938fd930 (diff)
downloadserenity-9149a519f5f1bbe0ad821fb1a6a408663fd3741d.zip
printf: Support printing negative values with %f or %g.
Diffstat (limited to 'AK/PrintfImplementation.h')
-rw-r--r--AK/PrintfImplementation.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/AK/PrintfImplementation.h b/AK/PrintfImplementation.h
index a115f78c19..091b5b4334 100644
--- a/AK/PrintfImplementation.h
+++ b/AK/PrintfImplementation.h
@@ -107,6 +107,16 @@ template<typename PutChFunc>
}
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)
{
dword divisor = 134217728;
@@ -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