big: Add Frobenius-Underwood.

This commit is contained in:
Jeroen van Rijn
2021-09-03 01:25:18 +02:00
parent 7fa04fa018
commit eecc786bd2
4 changed files with 117 additions and 18 deletions
+7 -8
View File
@@ -84,7 +84,7 @@ print :: proc(name: string, a: ^Int, base := i8(10), print_name := true, newline
}
}
// printf :: fmt.printf;
printf :: fmt.printf;
demo :: proc() {
a, b, c, d, e, f, res := &Int{}, &Int{}, &Int{}, &Int{}, &Int{}, &Int{}, &Int{};
@@ -93,16 +93,15 @@ demo :: proc() {
err: Error;
prime: bool;
trials := 1;
set(c, "3317044064679887385961981");
set(a, "3317044064679887385961981"); // Composite: 1287836182261 × 2575672364521
trials := number_of_rabin_miller_trials(internal_count_bits(a));
{
SCOPED_TIMING(.is_prime);
prime, err = internal_int_is_prime(c, trials);
prime, err = internal_int_is_prime(a, trials);
}
//print("prime: ", c);
fmt.printf("%v %v\n", prime, err);
print("Candidate prime: ", a);
fmt.printf("%v Miller-Rabin trials needed.\n", trials);
fmt.printf("Is prime: %v, Error: %v\n", prime, err);
}
main :: proc() {