|
1 /* |
|
2 * Simple test driver for MPI library |
|
3 * |
|
4 * Test 2: Basic addition and subtraction test |
|
5 * |
|
6 * This Source Code Form is subject to the terms of the Mozilla Public |
|
7 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
9 |
|
10 #include <stdio.h> |
|
11 #include <stdlib.h> |
|
12 #include <string.h> |
|
13 #include <ctype.h> |
|
14 #include <limits.h> |
|
15 |
|
16 #include "mpi.h" |
|
17 |
|
18 int main(int argc, char *argv[]) |
|
19 { |
|
20 mp_int a, b, c; |
|
21 |
|
22 if(argc < 3) { |
|
23 fprintf(stderr, "Usage: %s <a> <b>\n", argv[0]); |
|
24 return 1; |
|
25 } |
|
26 |
|
27 printf("Test 2: Basic addition and subtraction\n\n"); |
|
28 |
|
29 mp_init(&a); |
|
30 mp_init(&b); |
|
31 |
|
32 mp_read_radix(&a, argv[1], 10); |
|
33 mp_read_radix(&b, argv[2], 10); |
|
34 printf("a = "); mp_print(&a, stdout); fputc('\n', stdout); |
|
35 printf("b = "); mp_print(&b, stdout); fputc('\n', stdout); |
|
36 |
|
37 mp_init(&c); |
|
38 printf("c = a + b\n"); |
|
39 |
|
40 mp_add(&a, &b, &c); |
|
41 printf("c = "); mp_print(&c, stdout); fputc('\n', stdout); |
|
42 |
|
43 printf("c = a - b\n"); |
|
44 |
|
45 mp_sub(&a, &b, &c); |
|
46 printf("c = "); mp_print(&c, stdout); fputc('\n', stdout); |
|
47 |
|
48 mp_clear(&c); |
|
49 mp_clear(&b); |
|
50 mp_clear(&a); |
|
51 |
|
52 return 0; |
|
53 } |