spielwiese
Last change
on this file since 84250a6 was
84250a6,
checked in by Jens Schmidt <schmidt@…>, 27 years ago
|
#include <config.h> added
git-svn-id: file:///usr/local/Singular/svn/trunk@142 2c84dea3-7e68-4137-9b89-c4e89433aadc
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Line | |
---|
1 | // emacs edit mode for this file is -*- C++ -*- |
---|
2 | // $Id: ffops.cc,v 1.3 1997-04-08 16:04:39 schmidt Exp $ |
---|
3 | |
---|
4 | /* |
---|
5 | $Log: not supported by cvs2svn $ |
---|
6 | Revision 1.2 1996/06/18 12:05:42 stobbe |
---|
7 | "ff_biginv: changed long's to long long int. |
---|
8 | " |
---|
9 | |
---|
10 | Revision 1.1 1996/06/18 06:57:00 stobbe |
---|
11 | "Now the functionality to handle prime numbers that are bigger than 2^15. |
---|
12 | This results in various changes and some new functions. |
---|
13 | " |
---|
14 | |
---|
15 | Revision 1.0 1996/05/17 10:59:46 stobbe |
---|
16 | Initial revision |
---|
17 | |
---|
18 | */ |
---|
19 | |
---|
20 | #include <config.h> |
---|
21 | |
---|
22 | #include "assert.h" |
---|
23 | |
---|
24 | #include "cf_defs.h" |
---|
25 | #include "ffops.h" |
---|
26 | |
---|
27 | int ff_prime = 31991; |
---|
28 | int ff_halfprime = 31991 / 2; |
---|
29 | bool ff_big = false; |
---|
30 | short * ff_invtab = new short [32767]; |
---|
31 | |
---|
32 | void ff_setprime ( const int p ) |
---|
33 | { |
---|
34 | ff_prime = p; |
---|
35 | ff_halfprime = ff_prime / 2; |
---|
36 | if ( ! ff_big ) |
---|
37 | for ( int i = 0; i < ff_prime; i++ ) ff_invtab[i] = 0; |
---|
38 | } |
---|
39 | |
---|
40 | int ff_newinv ( const int a ) |
---|
41 | { |
---|
42 | int u, r0 = a, r1 = ff_prime, q0 = 1, q1 = 0; |
---|
43 | while ( ( r0 > 0 ) && ( r1 > 0 ) ) { |
---|
44 | u = r0 / r1; |
---|
45 | r0 = r0 % r1; |
---|
46 | q0 = u*q1 + q0; |
---|
47 | if ( r0 > 0 ) { |
---|
48 | u = r1 / r0; |
---|
49 | r1 = r1 % r0; |
---|
50 | q1 = u*q0 + q1; |
---|
51 | } |
---|
52 | } |
---|
53 | if ( r0 == 0 ) |
---|
54 | return (ff_invtab[a] = -q1); |
---|
55 | else |
---|
56 | return (ff_invtab[a] = q0); |
---|
57 | } |
---|
58 | |
---|
59 | int ff_biginv ( const int a ) |
---|
60 | { |
---|
61 | long long int u, r0 = a, r1 = ff_prime, q0 = 1, q1 = 0; |
---|
62 | while ( ( r0 > 0 ) && ( r1 > 0 ) ) { |
---|
63 | u = r0 / r1; |
---|
64 | r0 = r0 % r1; |
---|
65 | q0 = u*q1 + q0; |
---|
66 | if ( r0 > 0 ) { |
---|
67 | u = r1 / r0; |
---|
68 | r1 = r1 % r0; |
---|
69 | q1 = u*q0 + q1; |
---|
70 | } |
---|
71 | } |
---|
72 | if ( r0 == 0 ) |
---|
73 | return -(int)q1; |
---|
74 | else |
---|
75 | return (int)q0; |
---|
76 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.