Polly 20.0.0git
findprime.c
Go to the documentation of this file.
1/*
2 Name: findprime.c
3 Purpose: Find probable primes.
4 Author: M. J. Fromberger
5
6 Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
7
8 Notes:
9 Find the first prime number in sequence starting from the given value.
10 Demonstrates the use of mp_int_find_prime().
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in
20 all copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29 */
30
31#include <stdio.h>
32
33#include "iprime.h"
34
35int main(int argc, char *argv[]) {
36 char buf[4096];
37 mpz_t seed;
39
40 if (argc < 2) {
41 fprintf(stderr, "Usage: %s <start-value>\n", argv[0]);
42 return 1;
43 }
44
45 mp_int_init(&seed);
46 if ((res = mp_int_read_string(&seed, 10, argv[1])) != MP_OK) {
47 fprintf(stderr, "%s: error reading `%s': %d\n", argv[0], argv[1], res);
48 return 2;
49 }
50
51 if (mp_int_compare_value(&seed, 131) <= 0) {
52 fprintf(stderr, "%s: please enter a start value > 131\n", argv[0]);
53 return 1;
54 }
55
56 if ((res = mp_int_find_prime(&seed)) != MP_TRUE) {
57 fprintf(stderr, "%s: error finding prime: %d\n", argv[0], res);
58 return 2;
59 }
60
61 mp_int_to_string(&seed, 10, buf, sizeof(buf));
62 printf("=> %s\n", buf);
63
64 mp_int_clear(&seed);
65
66 return 0;
67}
int mp_result
Definition: imath/imath.h:40
mp_result mp_int_find_prime(mp_int z)
Definition: iprime.c:83
const char * res
Definition: isl_test.c:775
#define mp_int_to_string
Definition: wrap.h:122
#define mp_int_clear
Definition: wrap.h:72
#define mp_int_init
Definition: wrap.h:94
#define mp_int_read_string
Definition: wrap.h:109
#define MP_TRUE
Definition: wrap.h:11
#define mp_int_compare_value
Definition: wrap.h:76
#define MP_OK
Definition: wrap.h:9