1 | // emacs edit mode for this file is -*- C++ -*- |
---|
2 | // $Id: ffops.h,v 1.1 1996-06-18 06:57:00 stobbe Exp $ |
---|
3 | |
---|
4 | #ifndef INCL_FFOPS_H |
---|
5 | #define INCL_FFOPS_H |
---|
6 | |
---|
7 | /* |
---|
8 | $Log: not supported by cvs2svn $ |
---|
9 | Revision 1.0 1996/05/17 10:59:40 stobbe |
---|
10 | Initial revision |
---|
11 | |
---|
12 | */ |
---|
13 | |
---|
14 | #include "cf_globals.h" |
---|
15 | #include "cf_switches.h" |
---|
16 | |
---|
17 | extern int ff_prime; |
---|
18 | extern int ff_halfprime; |
---|
19 | extern short * ff_invtab; |
---|
20 | extern bool ff_big; |
---|
21 | |
---|
22 | int ff_newinv ( const int ); |
---|
23 | int ff_biginv ( const int ); |
---|
24 | void ff_setprime ( const int ); |
---|
25 | |
---|
26 | inline int ff_norm ( const int a ) |
---|
27 | { |
---|
28 | int n = a % ff_prime; |
---|
29 | if ( n < 0 ) |
---|
30 | return n + ff_prime; |
---|
31 | else |
---|
32 | return n; |
---|
33 | } |
---|
34 | |
---|
35 | inline int ff_symmetric( const int a ) |
---|
36 | { |
---|
37 | if ( cf_glob_switches.isOn( SW_SYMMETRIC_FF ) ) |
---|
38 | return ( a > ff_halfprime ) ? a - ff_prime : a; |
---|
39 | else |
---|
40 | return a; |
---|
41 | } |
---|
42 | |
---|
43 | inline int ff_longnorm ( const long a ) |
---|
44 | { |
---|
45 | int n = (int)(a % (long)ff_prime); |
---|
46 | if ( n < 0 ) |
---|
47 | return n + ff_prime; |
---|
48 | else |
---|
49 | return n; |
---|
50 | } |
---|
51 | |
---|
52 | inline int ff_bignorm ( const long long int a ) |
---|
53 | { |
---|
54 | int n = (int)(a % (long long int)ff_prime); |
---|
55 | if ( n < 0 ) |
---|
56 | return n + ff_prime; |
---|
57 | else |
---|
58 | return n; |
---|
59 | } |
---|
60 | |
---|
61 | inline int ff_add ( const int a, const int b ) |
---|
62 | { |
---|
63 | return ff_norm( a + b ); |
---|
64 | } |
---|
65 | |
---|
66 | inline int ff_sub ( const int a, const int b ) |
---|
67 | { |
---|
68 | return ff_norm( a - b ); |
---|
69 | } |
---|
70 | |
---|
71 | inline int ff_neg ( const int a ) |
---|
72 | { |
---|
73 | return ff_norm( -a ); |
---|
74 | } |
---|
75 | |
---|
76 | inline int ff_mul ( const int a, const int b ) |
---|
77 | { |
---|
78 | if ( ff_big ) |
---|
79 | return ff_bignorm( (long long int)a * (long long int)b ); |
---|
80 | else |
---|
81 | return ff_longnorm ( (long)a * (long)b ); |
---|
82 | } |
---|
83 | |
---|
84 | inline int ff_inv ( const int a ) |
---|
85 | { |
---|
86 | if ( ff_big ) |
---|
87 | return ff_biginv( a ); |
---|
88 | else { |
---|
89 | register b; |
---|
90 | if ( (b = (int)(ff_invtab[a])) ) |
---|
91 | return b; |
---|
92 | else |
---|
93 | return ff_newinv( a ); |
---|
94 | } |
---|
95 | |
---|
96 | } |
---|
97 | |
---|
98 | inline int ff_div ( const int a, const int b ) |
---|
99 | { |
---|
100 | return ff_mul( a, ff_inv( b ) ); |
---|
101 | } |
---|
102 | |
---|
103 | #endif /* INCL_FFOPS_H */ |
---|