-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdecimal.h
60 lines (54 loc) · 1.79 KB
/
decimal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#include <vector>
#include <string>
#include <type_traits>
#include <limits>
/*
* Not intended for production use, just something to provide load for testing
* other stuff - hence base being fixed at 10 and there being no sign bit.
*/
namespace kaiu {
class decimal {
public:
using digit = char;
decimal();
template <typename T, typename = typename std::enable_if<std::numeric_limits<T>::is_integer>::type>
decimal(T val);
decimal(const std::string& val);
explicit operator std::string() const;
explicit operator bool() const;
template <typename T, typename = typename std::enable_if<std::numeric_limits<T>::is_integer>::type>
explicit operator T() const;
digit& operator [](const size_t index);
digit operator [](const size_t index) const;
size_t length() const;
decimal operator +=(const decimal& b);
decimal operator +(const decimal& b) const;
decimal operator ++();
decimal operator -=(const decimal& b);
decimal operator -(const decimal& b) const;
decimal operator --();
decimal operator *(const decimal& b) const;
decimal operator *=(const decimal& b);
/* Haha ***k you `if (!value) { ... }` */
decimal operator !() const;
bool operator ==(const decimal& b) const;
bool operator !=(const decimal& b) const;
bool operator >(const decimal& b) const;
bool operator >=(const decimal& b) const;
bool operator <(const decimal& b) const;
bool operator <=(const decimal& b) const;
template <typename T, typename = typename std::enable_if<std::numeric_limits<T>::is_integer>::type>
bool operator ==(const T& b) const;
static decimal parallel_multiply(const decimal&, const decimal&);
private:
std::vector<digit> digits;
void remove_lz();
char relation_to(const decimal& b) const;
bool isZero() const;
bool isUnity() const;
};
}
#ifndef decimal_tcc
#include "decimal.tcc"
#endif