diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-01-17 19:35:54 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-01-17 19:35:54 +0100 |
| commit | ece9b2e4c547c986fd9e2bb4b7d97287be5621fb (patch) | |
| tree | 69496ab1f62785f9ad5ba1c3b366c5884712212d | |
| parent | 38efc7d2df030d37e3f20efbce71fadad1294cef (diff) | |
| download | zmodn-ece9b2e4c547c986fd9e2bb4b7d97287be5621fb.tar.gz zmodn-ece9b2e4c547c986fd9e2bb4b7d97287be5621fb.zip | |
Fix bigint print
| -rw-r--r-- | bigint.h | 20 |
1 files changed, 14 insertions, 6 deletions
| @@ -124,14 +124,22 @@ public: | |||
| 124 | constexpr BigInt operator%=(const BigInt& z) { return *this = *this % z; } | 124 | constexpr BigInt operator%=(const BigInt& z) { return *this = *this % z; } |
| 125 | 125 | ||
| 126 | friend std::ostream& operator<<(std::ostream& os, const BigInt<N, E>& z) { | 126 | friend std::ostream& operator<<(std::ostream& os, const BigInt<N, E>& z) { |
| 127 | bool fl = false; | 127 | if (z == 0) { |
| 128 | os << "0"; | ||
| 129 | return os; | ||
| 130 | } | ||
| 131 | |||
| 128 | if (!z.sign) | 132 | if (!z.sign) |
| 129 | os << "-"; | 133 | os << "-"; |
| 130 | for (int i = z.D-1; i >= 0; i--) | 134 | |
| 131 | if (fl = fl || z.digits[i] != 0; fl) | 135 | int j; |
| 132 | os << z.digits[i]; | 136 | for (j = z.D-1; z.digits[j] == 0; j--) ; |
| 133 | if (z == 0) | 137 | os << z.digits[j]; // Top digit is not padded |
| 134 | os << "0"; | 138 | |
| 139 | for (int i = j-1; i >= 0; i--) { | ||
| 140 | std::string num = std::to_string(z.digits[i]); | ||
| 141 | os << std::string(E - num.length(), '0') << num; | ||
| 142 | } | ||
| 135 | return os; | 143 | return os; |
| 136 | } | 144 | } |
| 137 | 145 | ||
