-
Notifications
You must be signed in to change notification settings - Fork 0
/
decimal.h
28 lines (21 loc) · 904 Bytes
/
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
#define MAX_PRECISION 18
typedef long long Decimal;
typedef struct{
char precision;
char scale;
}DecimalSchema;
template<typename T>
__inline__ T max(T t1, T t2) { return t1 > t2 ? t1: t2;}
template<typename T>
__inline__ T min(T t1, T t2) { return t1 < t2 ? t1: t2;}
void DecimalToString(DecimalSchema sch, Decimal d, char * str);
DecimalSchema StringToDecimal(const char* str, Decimal &d);
/**
* d1+d2=d3
* return 0, success
* -1, overflow
**/
int add(DecimalSchema sch1, Decimal d1, DecimalSchema sch2, Decimal d2, DecimalSchema &sch3, Decimal &d3);
int sub(DecimalSchema sch1, Decimal d1, DecimalSchema sch2, Decimal d2, DecimalSchema &sch3, Decimal &d3);
int multiply(DecimalSchema sch1, Decimal d1, DecimalSchema sch2, Decimal d2, DecimalSchema &sch3, Decimal &d3);
int div(DecimalSchema sch1, Decimal d1, DecimalSchema sch2, Decimal d2, DecimalSchema &sch3, Decimal &d3);