Oberon || Library || Module Index || Search Engine || Definition || Module
CONST composite = 0; prime = 1; indefinite = 2; TYPE Test = POINTER TO TestRec; TYPE TestRec = RECORD (Disciplines.ObjectRec) END; TYPE PerformTestProc = PROCEDURE(test: Test; value: IntOperations.Operand; VAR p: REAL): INTEGER; TYPE Interface = POINTER TO InterfaceRec; TYPE InterfaceRec = RECORD (Objects.ObjectRec) performTest: PerformTestProc; END;
PROCEDURE Init(test: Test; if: Interface); PROCEDURE PerformTest(test: Test; value: IntOperations.Operand; VAR p: REAL): INTEGER;
The interface procedure should meet the specification following:
Init is called by modules which implement a primality test algorithm to connect the interface if to the prime test test.
PerformTest tests the given value and returns composite if value is definitely not prime, returns prime if value is surely prime and returns indefinite if value may be prime. If a probabilistic primality testing algorithm is used, then p in (0..1) indicates the probability of value being prime. Then reiterations of the test improve the result, because the tests are independent. If the test returns indefinite and p is 0, then really no prediction can be made and it is recommended to use another testing algorithm.
Oberon || Library || Module Index || Search Engine || Definition || Module