diff options
| Commit | f788177bd2b63ea92872ce49bee5d9975227ccad (patch) | |
|---|---|---|
| Author | 2022-05-29 12:59:39 +0300 | |
| Committer | 2022-05-29 12:59:39 +0300 | |
| Files | b26792d28e11e8b2c38e35b01547d0e77616a1cf /src | |
| FMI-OOP-P2_Tables-f788177bd2b63ea92872ce49bee5d9975227ccad.tar FMI-OOP-P2_Tables-f788177bd2b63ea92872ce49bee5d9975227ccad.tar.gz FMI-OOP-P2_Tables-f788177bd2b63ea92872ce49bee5d9975227ccad.zip | ||
| Parent | f192b81a575a9599c52713ea9eec66a95a70a561 (diff) | |
Autocommit at 29.05.2022 @ 12:59
2 files changed, 22 insertions, 0 deletions
| -rw-r--r-- | src/Generic/String/String.cpp | 18 | ||||
| -rw-r--r-- | src/Generic/String/String.h | 4 |
diff --git a/src/Generic/String/String.cpp b/src/Generic/String/String.cpp index 66e9ad4..d37e9b7 100644 --- a/src/Generic/String/String.cpp +++ b/src/Generic/String/String.cpp @@ -77,6 +77,24 @@ String& String::operator+=(unsigned number) { return *this; } +/*! + * Converts the number to a C-style string and then uses += to append it. + */ +String& String::operator+=(double number) { + unsigned tempLen = 0; + for (unsigned tmp = number; tmp > 0 || tempLen == 0; tmp /= 10) + tempLen++; + + char* tmp = new char[tempLen + 1]; + tmp[tempLen] = '\0'; + for (unsigned i = tempLen - 1; i < tempLen; i--, number /= 10) + tmp[i] = number % 10 + '0'; + + *this += tmp; + delete[] tmp; + return *this; +} + String::String() : String("") {} String::String(const String& other) { diff --git a/src/Generic/String/String.h b/src/Generic/String/String.h index 84fbe9c..f30151a 100644 --- a/src/Generic/String/String.h +++ b/src/Generic/String/String.h @@ -8,6 +8,8 @@ #include <istream> #include <ostream> +#define DOUBLE_PRECISION 1e10 + class String { char* str; unsigned length; @@ -31,6 +33,8 @@ public: String& operator+=(const char* str); //! Appends a number String& operator+=(unsigned number); + //! Appends a number + String& operator+=(double number); String(); String(const String& other); |
