 Timestamp:
 Apr 14, 1998, 5:17:16 PM (26 years ago)
 Branches:
 (u'spielwiese', '2fa36c576e6a4ddbb1093b43c7f8e9835e17e52a')
 Children:
 43580ac75b66829291eab1ba0e001075ecf7e429
 Parents:
 9388d44d66568ee4423a1b5b0cb6898306a4928b
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

factory/ffops.cc
r9388d4 rb7c8bd 1 1 /* emacs edit mode for this file is * C++ * */ 2 /* $Id: ffops.cc,v 1. 7 19980311 09:40:31 schmidtExp $ */2 /* $Id: ffops.cc,v 1.8 19980414 15:17:16 pohl Exp $ */ 3 3 4 4 #include <config.h> … … 16 16 short * ff_invtab = new short [32767]; 17 17 18 #ifdef __MWERKS__ 19 #include <stuff_64.h> 20 int ff_mul( const int a, const int b ) 21 { 22 Int_64 c; 23 unsigned int ua, ub; 24 int res; 25 26 if ((!a)  (!b)) return 0; 27 if (a>0) 28 ua = a; 29 else 30 ua = a; 31 if (b>0) 32 ub = b; 33 else 34 ub = b; 35 mul_64(&c, ua, ub); 36 res = rem_64(&c, ff_prime); 37 if ((a>0) != (b>0)) 38 res = ff_primeres; 39 return res; 40 } 41 #endif 42 18 43 void ff_setprime ( const int p ) 19 44 { … … 28 53 int ff_newinv ( const int a ) 29 54 { 30 int u, r0 = a, r1 = ff_prime, q0 = 1, q1 = 0; 31 while ( ( r0 > 0 ) && ( r1 > 0 ) ) { 32 u = r0 / r1; 33 r0 = r0 % r1; 34 q0 = u*q1 + q0; 35 if ( r0 > 0 ) { 36 u = r1 / r0; 37 r1 = r1 % r0; 38 q1 = u*q0 + q1; 39 } 55 int p, q, r1, r2, y1, y2; 56 if (a < 2) 57 return (ff_invtab[a] = a); 58 r1 = p = ff_prime; 59 q = r1 / a; 60 y1 = q; 61 r1 = a * q; 62 if (r1 == 1) 63 { 64 y1 += p; 65 ff_invtab[y1] = a; 66 return (ff_invtab[a] = y1); 40 67 } 41 if ( r0 == 0 ) 42 return (ff_invtab[a] = q1); 43 else 44 return (ff_invtab[a] = q0); 68 r2 = a; 69 y2 = 1; 70 for (;;) 71 { 72 q = r2 / r1; 73 y2 = y1 * q; 74 r2 = r1 * q; 75 if (r2 == 1) 76 { 77 if (y2 < 0) 78 y2 += p; 79 ff_invtab[y2] = a; 80 return (ff_invtab[a] = y2); 81 } 82 q = r1 / r2; 83 y1 = y2 * q; 84 r1 = r2 * q; 85 if (r1 == 1) 86 { 87 if (y1 < 0) 88 y1 += p; 89 ff_invtab[y1] = a; 90 return (ff_invtab[a] = y1); 91 } 92 } 45 93 } 46 94 47 95 int ff_biginv ( const int a ) 48 96 { 49 INT64 u, r0 = a, r1 = ff_prime, q0 = 1, q1 = 0; 50 while ( ( r0 > 0 ) && ( r1 > 0 ) ) { 51 u = r0 / r1; 52 r0 = r0 % r1; 53 q0 = u*q1 + q0; 54 if ( r0 > 0 ) { 55 u = r1 / r0; 56 r1 = r1 % r0; 57 q1 = u*q0 + q1; 58 } 97 int p, q, r1, r2, y1, y2; 98 if (a < 2) 99 return a; 100 r1 = p = ff_prime; 101 q = r1 / a; 102 y1 = q; 103 r1 = a * q; 104 if (r1 == 1) 105 return p + y1; 106 r2 = a; 107 y2 = 1; 108 for (;;) 109 { 110 q = r2 / r1; 111 y2 = y1 * q; 112 r2 = r1 * q; 113 if (r2 == 1) 114 { 115 if (y2 > 0) 116 return y2; 117 else 118 return p + y2; 119 } 120 q = r1 / r2; 121 y1 = y2 * q; 122 r1 = r2 * q; 123 if (r1 == 1) 124 { 125 if (y1 > 0) 126 return y1; 127 else 128 return p + y1; 129 } 59 130 } 60 if ( r0 == 0 )61 return (int)q1;62 else63 return (int)q0;64 131 }
Note: See TracChangeset
for help on using the changeset viewer.