1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | /* $Id: ffops.h,v 1.7 2000-04-27 10:07:30 obachman Exp $ */ |
---|
3 | |
---|
4 | #ifndef INCL_FFOPS_H |
---|
5 | #define INCL_FFOPS_H |
---|
6 | |
---|
7 | #include <config.h> |
---|
8 | |
---|
9 | #include "cf_globals.h" |
---|
10 | |
---|
11 | extern int ff_prime; |
---|
12 | extern int ff_halfprime; |
---|
13 | extern short * ff_invtab; |
---|
14 | extern bool ff_big; |
---|
15 | |
---|
16 | int ff_newinv ( const int ); |
---|
17 | int ff_biginv ( const int ); |
---|
18 | void ff_setprime ( const int ); |
---|
19 | |
---|
20 | inline int ff_norm ( const int a ) |
---|
21 | { |
---|
22 | int n = a % ff_prime; |
---|
23 | if ( n < 0 ) |
---|
24 | return n + ff_prime; |
---|
25 | else |
---|
26 | return n; |
---|
27 | } |
---|
28 | |
---|
29 | inline int ff_symmetric( const int a ) |
---|
30 | { |
---|
31 | if ( cf_glob_switches.isOn( SW_SYMMETRIC_FF ) ) |
---|
32 | return ( a > ff_halfprime ) ? a - ff_prime : a; |
---|
33 | else |
---|
34 | return a; |
---|
35 | } |
---|
36 | |
---|
37 | inline int ff_longnorm ( const long a ) |
---|
38 | { |
---|
39 | int n = (int)(a % (long)ff_prime); |
---|
40 | if ( n < 0 ) |
---|
41 | return n + ff_prime; |
---|
42 | else |
---|
43 | return n; |
---|
44 | } |
---|
45 | |
---|
46 | #ifndef __MWERKS__ |
---|
47 | inline int ff_bignorm ( const INT64 a ) |
---|
48 | { |
---|
49 | int n = (int)(a % (INT64)ff_prime); |
---|
50 | if ( n < 0 ) |
---|
51 | return n + ff_prime; |
---|
52 | else |
---|
53 | return n; |
---|
54 | } |
---|
55 | #endif |
---|
56 | |
---|
57 | inline int ff_add ( const int a, const int b ) |
---|
58 | { |
---|
59 | return ff_norm( a + b ); |
---|
60 | } |
---|
61 | |
---|
62 | inline int ff_sub ( const int a, const int b ) |
---|
63 | { |
---|
64 | return ff_norm( a - b ); |
---|
65 | } |
---|
66 | |
---|
67 | inline int ff_neg ( const int a ) |
---|
68 | { |
---|
69 | return ff_norm( -a ); |
---|
70 | } |
---|
71 | |
---|
72 | #ifdef __MWERKS__ |
---|
73 | int ff_mul ( const int a, const int b ); |
---|
74 | #else |
---|
75 | inline int ff_mul ( const int a, const int b ) |
---|
76 | { |
---|
77 | if ( ff_big ) |
---|
78 | return ff_bignorm( (INT64)a * (INT64)b ); |
---|
79 | else |
---|
80 | return ff_longnorm ( (long)a * (long)b ); |
---|
81 | } |
---|
82 | #endif |
---|
83 | |
---|
84 | inline int ff_inv ( const int a ) |
---|
85 | { |
---|
86 | if ( ff_big ) |
---|
87 | return ff_biginv( a ); |
---|
88 | else { |
---|
89 | register int 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 */ |
---|