2004-03-03 21:24:06 +01:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
eval_isprime(void)
|
|
|
|
{
|
|
|
|
push(cadr(p1));
|
|
|
|
eval();
|
|
|
|
p1 = pop();
|
2006-01-10 20:43:56 +01:00
|
|
|
if (isnonnegativeinteger(p1) && mprime(p1->u.q.a))
|
|
|
|
push_integer(1);
|
|
|
|
else
|
|
|
|
push_integer(0);
|
2004-03-03 21:24:06 +01:00
|
|
|
}
|
|
|
|
|
2007-05-08 16:57:30 +02:00
|
|
|
#if SELFTEST
|
|
|
|
|
2004-03-03 21:24:06 +01:00
|
|
|
static char *s[] = {
|
|
|
|
|
2006-01-10 20:43:56 +01:00
|
|
|
// 0 and 1 are not prime numbers
|
|
|
|
|
|
|
|
"isprime(0)",
|
|
|
|
"0",
|
|
|
|
|
|
|
|
"isprime(1)",
|
|
|
|
"0",
|
|
|
|
|
2004-03-03 21:24:06 +01:00
|
|
|
"isprime(13)",
|
2006-01-10 20:43:56 +01:00
|
|
|
"1",
|
2004-03-03 21:24:06 +01:00
|
|
|
|
|
|
|
"isprime(14)",
|
2006-01-10 20:43:56 +01:00
|
|
|
"0",
|
2004-03-03 21:24:06 +01:00
|
|
|
|
|
|
|
// from the Prime Curios web page
|
|
|
|
|
|
|
|
"isprime(9007199254740991)",
|
2006-01-10 20:43:56 +01:00
|
|
|
"0",
|
2004-03-03 21:24:06 +01:00
|
|
|
|
|
|
|
// The largest prime that JavaScript supports
|
|
|
|
|
|
|
|
"isprime(2^53 - 111)",
|
2006-01-10 20:43:56 +01:00
|
|
|
"1",
|
2004-03-03 21:24:06 +01:00
|
|
|
|
|
|
|
// misc. primes
|
|
|
|
|
|
|
|
"isprime(2^50-71)",
|
2006-01-10 20:43:56 +01:00
|
|
|
"1",
|
2004-03-03 21:24:06 +01:00
|
|
|
|
|
|
|
"isprime(2^40-87)",
|
2006-01-10 20:43:56 +01:00
|
|
|
"1",
|
2004-03-03 21:24:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
test_isprime(void)
|
|
|
|
{
|
|
|
|
test(__FILE__, s, sizeof s / sizeof (char *));
|
|
|
|
}
|
2007-05-08 16:57:30 +02:00
|
|
|
|
|
|
|
#endif
|