diff options
author | tomsmeding <tom.smeding@gmail.com> | 2019-04-20 19:41:16 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2019-04-20 19:41:16 +0200 |
commit | ccade8e6ed96fb48b329d22aaa4c8d0826b3c8d1 (patch) | |
tree | b9389a557869a38d0cdb9de02247abf1446e5db3 /aberth/util.cpp | |
parent | dc6f869c48c267e2091d686a66209c4f741d62e4 (diff) |
Move some code out of main.cpp
Diffstat (limited to 'aberth/util.cpp')
-rw-r--r-- | aberth/util.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/aberth/util.cpp b/aberth/util.cpp new file mode 100644 index 0000000..b8f6edc --- /dev/null +++ b/aberth/util.cpp @@ -0,0 +1,27 @@ +#include "util.h" + + +ostream& operator<<(ostream &os, const Poly &p) { + static const char *supers[10] = { + "⁰", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹" + }; + + os << p[0]; + + for (int i = 1; i < (int)p.size(); i++) { + if (p[i] < 0) os << " - " << -p[i]; + else if (p[i] > 0) os << " + " << p[i]; + else continue; + + os << "x"; + + if (i == 1) continue; + + ostringstream ss; + ss << i; + string s = ss.str(); + for (char c : s) os << supers[c - '0']; + } + + return os; +} |