From d2cdb5796067925ef58cba9e38976792b26a2fc5 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 29 May 2022 13:09:42 +0300 Subject: Autocommit at 29.05.2022 @ 13:09 --- src/Generic/String/String.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/Generic/String/String.cpp') diff --git a/src/Generic/String/String.cpp b/src/Generic/String/String.cpp index d9cc235..ed096e8 100644 --- a/src/Generic/String/String.cpp +++ b/src/Generic/String/String.cpp @@ -59,6 +59,17 @@ String& String::operator+=(const char* str) { return *this; } +/*! + * Converts the number to a C-style string and then uses += to append it. + */ +String& String::operator+=(int number) { + if (number < 0) { + *this += "-"; + number *= -1; + } + return *this += (unsigned)number; +} + /*! * Converts the number to a C-style string and then uses += to append it. */ @@ -81,8 +92,12 @@ String& String::operator+=(unsigned number) { * Converts the number to a C-style string and then uses += to append it. */ String& String::operator+=(double number) { - if (number < 0) *this += "-"; - return ((*this += (unsigned)number) += ".") += (unsigned)((number - (unsigned)number) * DOUBLE_PRECISION); + if (number < 0) { + *this += "-"; + number *= -1; + } + return ((*this += (unsigned)number) += ".") + += (unsigned)((number - (unsigned)number) * DOUBLE_PRECISION); } String::String() : String("") {} -- cgit v1.3.1-23-gd82d