Преглед на файлове

Add a number format feature to the to_string() functions.

Sam Jaffe преди 4 години
родител
ревизия
e03d947e04
променени са 5 файла, в които са добавени 9 реда и са изтрити 5 реда
  1. 3 1
      include/math/bigdecimal.h
  2. 3 1
      include/math/biginteger.h
  3. 1 1
      include/math/decimal_format.h
  4. 1 1
      src/bigdecimal.cpp
  5. 1 1
      src/biginteger.cpp

+ 3 - 1
include/math/bigdecimal.h

@@ -10,6 +10,8 @@
 #include <string>
 #include <vector>
 
+#include "number_format.h"
+
 namespace math {
   class bigdecimal {
   private:
@@ -73,7 +75,7 @@ namespace math {
     friend bool operator>=(bigdecimal const &, bigdecimal const &);
     friend bool operator>(bigdecimal const &, bigdecimal const &);
 
-    std::string to_string() const;
+    std::string to_string(number_format fmt = {}) const;
 
   private:
     bigdecimal(bool, uint64_t);

+ 3 - 1
include/math/biginteger.h

@@ -10,6 +10,8 @@
 #include <string>
 #include <vector>
 
+#include "number_format.h"
+
 namespace math {
   class biginteger {
   private:
@@ -58,7 +60,7 @@ namespace math {
     friend biginteger & operator*=(biginteger &, biginteger const &);
     friend biginteger & operator/=(biginteger &, biginteger const &);
     // Output
-    std::string to_string() const;
+    std::string to_string(number_format fmt = {}) const;
     // Comparison
     friend bool operator==(biginteger const &, biginteger const &);
     friend bool operator!=(biginteger const &, biginteger const &);

+ 1 - 1
include/math/decimal_format.h

@@ -10,6 +10,6 @@
 
 namespace math {
 
-  struct decimal_format {};
+  struct number_format {};
 
 }

+ 1 - 1
src/bigdecimal.cpp

@@ -270,7 +270,7 @@ bool math::operator>(bigdecimal const & rhs, bigdecimal const & lhs) {
 bigdecimal const bigdecimal::ZERO{0}, bigdecimal::ONE{1},
     bigdecimal::NEGATIVE_ONE{-1};
 
-std::string bigdecimal::to_string() const {
+std::string bigdecimal::to_string(number_format fmt) const {
   size_t const decimal_split = size_t(std::max(0, steps_));
   int32_t const hidden = std::max(0, SEG_DIGITS * (-scale() / SEG_DIGITS));
   size_t const chars = SEG_DIGITS * data.size() + size_t(hidden);

+ 1 - 1
src/biginteger.cpp

@@ -195,7 +195,7 @@ bool math::operator>(biginteger const & rhs, biginteger const & lhs) {
 biginteger const biginteger::ZERO{0}, biginteger::ONE{1},
     biginteger::NEGATIVE_ONE{-1};
 
-std::string biginteger::to_string() const {
+std::string biginteger::to_string(number_format fmt) const {
   std::vector<char> output(biginteger::SEG_DIGITS * data.size() + 2, '\0');
   std::ptrdiff_t idx = 0;
   if (is_negative) {