forked from HTmonster/BigInt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EXAMPLE.c
58 lines (46 loc) · 1.21 KB
/
EXAMPLE.c
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
# define MAX_BIT_LEN 1000
#include"number.h"
int main() {
BigNum *op1, *op2, *rst;
printf("//////////// 演示示例 ///////////////\n");
while ((op1 = MakeNumFromIO()) == NULL);
// op1 = MakeNum("10000000000.3");
while ((op2 = MakeNumFromIO()) == NULL);
// op2 = MakeNum("-66.79.3");
printf("操作数 op1=");
ShowNum(op1);
printf("操作数 op2=");
ShowNum(op2);
printf("\n");
printf("两数比较 ");
int res = Compare(op1, op2);
switch (res) {
case 1:
printf("op1 > op2\n");
break;
case 0:
printf("op1 = op2\n");
break;
case -1:
printf("op1 < op2\n");
break;
default:
printf("");
}
rst = BigNum_ADD(op1, op2);
printf("加法结果:");
ShowNum(rst);
rst = BigNum_SUB(op1, op2);
printf("减法结果:");
ShowNum(rst);
rst = BigNum_MUL(op1, op2);
printf("乘法结果:");
ShowNum(rst);
rst = BigNum_DIV(op1, op2, 500); //tail 最多小数位数
printf("除法结果:");
ShowNum(rst);
printf("\n\n支持连环调用, 演示 op1 * op2 - 2 = ");
rst = BigNum_SUB(BigNum_MUL(op1, op2), MakeNum("2"));
ShowNum(rst);
return 0;
}