Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / isprime.cpp
blobca45f93bad63ac4e845c02c1c7eb2dc29ed307a9
1 #include "stdafx.h"
2 #include "defs.h"
4 void
5 eval_isprime(void)
7 push(cadr(p1));
8 eval();
9 p1 = pop();
10 if (isnonnegativeinteger(p1) && mprime(p1->u.q.a))
11 push_integer(1);
12 else
13 push_integer(0);
16 #if SELFTEST
18 static char *s[] = {
20 // 0 and 1 are not prime numbers
22 "isprime(0)",
23 "0",
25 "isprime(1)",
26 "0",
28 "isprime(13)",
29 "1",
31 "isprime(14)",
32 "0",
34 // from the Prime Curios web page
36 "isprime(9007199254740991)",
37 "0",
39 // The largest prime that JavaScript supports
41 "isprime(2^53 - 111)",
42 "1",
44 // misc. primes
46 "isprime(2^50-71)",
47 "1",
49 "isprime(2^40-87)",
50 "1",
53 void
54 test_isprime(void)
56 test(__FILE__, s, sizeof s / sizeof (char *));
59 #endif