File : w_pred.adb
1 ------------------------------------------------------------------------------
2 ------------------------------------------------------------------------------
3 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. --
4 -- --
5 -- (C) 2019 Stanislav Datskovskiy ( www.loper-os.org ) --
6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
7 -- --
8 -- You do not have, nor can you ever acquire the right to use, copy or --
9 -- distribute this software ; Should you use this software for any purpose, --
10 -- or copy and distribute it to anyone or in any manner, you are breaking --
11 -- the laws of whatever soi-disant jurisdiction, and you promise to --
12 -- continue doing so for the indefinite future. In any case, please --
13 -- always : read and understand any software ; verify any PGP signatures --
14 -- that you use - for any purpose. --
15 -- --
16 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
17 ------------------------------------------------------------------------------
18 ------------------------------------------------------------------------------
19
20 with Word_Ops; use Word_Ops;
21
22
23 -- Elementary Predicates on Words:
24 package body W_Pred is
25
26 -- Return 1 if N is equal to 0; otherwise return 0.
27 function W_ZeroP(N : in Word) return WBool is
28 begin
29 return W_Borrow(N, 1, N - 1);
30 end W_ZeroP;
31
32
33 -- Return 1 if N is unequal to 0; otherwise return 0.
34 function W_NZeroP(N : in Word) return WBool is
35 begin
36 return 1 xor W_ZeroP(N);
37 end W_NZeroP;
38
39
40 -- Return WBool-complement of N.
41 function W_Not(N : in WBool) return WBool is
42 begin
43 return 1 xor N;
44 end W_Not;
45
46
47 -- Return 1 if N is odd; otherwise return 0.
48 function W_OddP(N : in Word) return WBool is
49 begin
50 return 1 and N;
51 end W_OddP;
52
53
54 -- Return 1 if A is equal to B ; otherwise return 0.
55 function W_EqP(A : in Word; B : in Word) return WBool is
56 begin
57 return W_ZeroP(A xor B);
58 end W_EqP;
59
60
61 -- Return 1 if A is less than B ; otherwise return 0.
62 function W_LtP(A : in Word; B : in Word) return WBool is
63 begin
64 return W_Borrow(A, B, A - B);
65 end W_LtP;
66
67 end W_Pred;