Skip to content

Commit 3f6c801

Browse files
committed
Bugfix stoa not handling negative floating point numbers
1 parent 9453067 commit 3f6c801

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

klib/string.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,14 +512,20 @@ namespace klib::string::detail {
512512
else {
513513
int i = 0, k = 0;
514514

515+
// handle negative values
516+
if (value < static_cast<T>(0.f)) {
517+
str[k++] = '-';
518+
value *= -1;
519+
}
520+
515521
do {
516522
value /= 10;
517523
i++;
518524
}
519525
while (static_cast<int>(value) > 0);
520526

521527
// add the decimal seperator
522-
*(str + i) = '.';
528+
*(str + k + i) = '.';
523529

524530
value *= 10;
525531
auto n = static_cast<int>(value);

0 commit comments

Comments
 (0)