Rational representation
[ipdf/code.git] / src / arbint.cpp
1 #include "arbint.h"
2 #include <algorithm>
3 #include <cstring>
4 using namespace std;
5
6 /*
7 static bool addc(uint32_t a, uint32_t b, uint32_t * r)
8 {
9         volatile uint32_t carry = false;
10         volatile uint32_t result = a + b;
11         asm volatile
12         (
13                 "jc 1f;"
14                 "mov $0, %%eax;"
15                 "1:"
16                 : "=a" (carry)
17         );
18         *r = result;    
19         return (carry == 1);
20 }
21 */
22
23 namespace IPDF
24 {
25
26 Arbint::Arbint(int64_t i) : m_words(2), m_sign(false)
27 {
28         m_sign = i < 0;
29         memcpy(m_words.data(), &i, sizeof(int64_t));
30 }
31
32 string Arbint::Str() const
33 {
34         string s("");
35         for (unsigned i = 0; i < m_words.size(); ++i)
36         {
37                 uint32_t w = m_words[i];
38                 do
39                 {
40                         uint32_t q = w % 10;
41                         w /= 10;
42                         s += ('0' + q);
43                 }
44                 while (w > 0);
45                 if (i+1 < m_words.size()) s += ",";     
46         }
47         if (m_sign) s += '-';
48         reverse(s.begin(), s.end());
49         return s;
50 }
51
52 }

UCC git Repository :: git.ucc.asn.au