2
* Simple test driver for MPI library
4
* Test 3: Multiplication, division, and exponentiation test
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/. */
20
#define SQRT 1 /* define nonzero to get square-root test */
21
#define EXPT 0 /* define nonzero to get exponentiate test */
23
int main(int argc, char *argv[])
31
fprintf(stderr, "Usage: %s <a> <b>\n", argv[0]);
35
printf("Test 3: Multiplication and division\n\n");
41
mp_read_variable_radix(&a, argv[1], 10);
42
mp_read_variable_radix(&b, argv[2], 10);
43
printf("a = "); mp_print(&a, stdout); fputc('\n', stdout);
44
printf("b = "); mp_print(&b, stdout); fputc('\n', stdout);
47
printf("\nc = a * b\n");
50
printf("c = "); mp_print(&c, stdout); fputc('\n', stdout);
52
printf("\nc = b * 32523\n");
54
mp_mul_d(&b, 32523, &c);
55
printf("c = "); mp_print(&c, stdout); fputc('\n', stdout);
58
printf("\nc = a / b, d = a mod b\n");
60
mp_div(&a, &b, &c, &d);
61
printf("c = "); mp_print(&c, stdout); fputc('\n', stdout);
62
printf("d = "); mp_print(&d, stdout); fputc('\n', stdout);
65
printf("\nc = a / %d, r = a mod %d\n", ix, ix);
66
mp_div_d(&a, (mp_digit)ix, &c, &r);
67
printf("c = "); mp_print(&c, stdout); fputc('\n', stdout);
68
printf("r = %04X\n", r);
71
printf("\nc = a ** b\n");
73
printf("c = "); mp_print(&c, stdout); fputc('\n', stdout);
77
printf("\nc = 2^%d\n", ix);
79
printf("c = "); mp_print(&c, stdout); fputc('\n', stdout);
82
printf("\nc = sqrt(a)\n");
83
if((res = mp_sqrt(&a, &c)) != MP_OKAY) {
84
printf("mp_sqrt: %s\n", mp_strerror(res));
86
printf("c = "); mp_print(&c, stdout); fputc('\n', stdout);
88
printf("c^2 = "); mp_print(&c, stdout); fputc('\n', stdout);