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

AK: Print NaN and infinite numbers in PrintfImplementation

This commit is contained in:
Peter Ross 2022-03-01 19:50:19 +11:00 committed by Andreas Kling
parent feb19646df
commit 34108547b6
2 changed files with 41 additions and 1 deletions

View file

@ -9,6 +9,7 @@
#include <AK/Format.h>
#include <AK/StdLibExtras.h>
#include <AK/Types.h>
#include <math.h>
#include <stdarg.h>
#ifdef __serenity__
@ -165,7 +166,30 @@ ALWAYS_INLINE int print_double(PutChFunc putch, CharType*& bufptr, double number
u32 whole_width = (field_width >= precision + 1) ? field_width - precision - 1 : 0;
bool sign = number < 0;
bool sign = signbit(number);
bool nan = isnan(number);
bool inf = isinf(number);
if (nan || inf) {
for (unsigned i = 0; i < field_width - 3 - sign; i++) {
putch(bufptr, ' ');
length++;
}
if (sign) {
putch(bufptr, '-');
length++;
}
if (nan) {
putch(bufptr, 'n');
putch(bufptr, 'a');
putch(bufptr, 'n');
} else {
putch(bufptr, 'i');
putch(bufptr, 'n');
putch(bufptr, 'f');
}
return length + 3;
}
if (sign)
number = -number;