source: git/factory/ffops.cc @ f0596e

spielwiese
Last change on this file since f0596e was 493c477, checked in by Jens Schmidt <schmidt@…>, 27 years ago
o header fixed git-svn-id: file:///usr/local/Singular/svn/trunk@404 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 1.1 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2/* $Id: ffops.cc,v 1.4 1997-06-19 12:23:06 schmidt Exp $ */
3
4#include <config.h>
5
6#include "assert.h"
7
8#include "cf_defs.h"
9#include "ffops.h"
10
11int ff_prime = 31991;
12int ff_halfprime = 31991 / 2;
13bool ff_big = false;
14short * ff_invtab = new short [32767];
15
16void ff_setprime ( const int p )
17{
18    ff_prime = p;
19    ff_halfprime = ff_prime / 2;
20    if ( ! ff_big )
21        for ( int i = 0; i < ff_prime; i++ ) ff_invtab[i] = 0;
22}
23
24int ff_newinv ( const int a )
25{
26    int u, r0 = a, r1 = ff_prime, q0 = 1, q1 = 0;
27    while ( ( r0 > 0 ) && ( r1 > 0 ) ) {
28        u = r0 / r1;
29        r0 = r0 % r1;
30        q0 = u*q1 + q0;
31        if ( r0 > 0 ) {
32            u = r1 / r0;
33            r1 = r1 % r0;
34            q1 = u*q0 + q1;
35        }
36    }
37    if ( r0 == 0 )
38        return (ff_invtab[a] = -q1);
39    else
40        return (ff_invtab[a] = q0);
41}
42
43int ff_biginv ( const int a )
44{
45    long long int u, r0 = a, r1 = ff_prime, q0 = 1, q1 = 0;
46    while ( ( r0 > 0 ) && ( r1 > 0 ) ) {
47        u = r0 / r1;
48        r0 = r0 % r1;
49        q0 = u*q1 + q0;
50        if ( r0 > 0 ) {
51            u = r1 / r0;
52            r1 = r1 % r0;
53            q1 = u*q0 + q1;
54        }
55    }
56    if ( r0 == 0 )
57        return -(int)q1;
58    else
59        return (int)q0;
60}
Note: See TracBrowser for help on using the repository browser.