source: git/factory/ffops.cc @ 9c9e2a4

spielwiese
Last change on this file since 9c9e2a4 was 9c9e2a4, checked in by Jens Schmidt <schmidt@…>, 26 years ago
^M fix. Was: Thu 27.11.1997 22:30:00 Ruediger Stobbe <rstobbe@de.oracle.com> Factory Win NT Port, see ChangeLog for details git-svn-id: file:///usr/local/Singular/svn/trunk@951 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.6 1997-12-08 18:24:37 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    if ( p != ff_prime ) {
19        ff_prime = p;
20        ff_halfprime = ff_prime / 2;
21        if ( ! ff_big )
22            for ( int i = 0; i < ff_prime; i++ ) ff_invtab[i] = 0;
23    }
24}
25
26int ff_newinv ( const int a )
27{
28    int u, r0 = a, r1 = ff_prime, q0 = 1, q1 = 0;
29    while ( ( r0 > 0 ) && ( r1 > 0 ) ) {
30        u = r0 / r1;
31        r0 = r0 % r1;
32        q0 = u*q1 + q0;
33        if ( r0 > 0 ) {
34            u = r1 / r0;
35            r1 = r1 % r0;
36            q1 = u*q0 + q1;
37        }
38    }
39    if ( r0 == 0 )
40        return (ff_invtab[a] = -q1);
41    else
42        return (ff_invtab[a] = q0);
43}
44
45int ff_biginv ( const int a )
46{
47    INT64 u, r0 = a, r1 = ff_prime, q0 = 1, q1 = 0;
48    while ( ( r0 > 0 ) && ( r1 > 0 ) ) {
49        u = r0 / r1;
50        r0 = r0 % r1;
51        q0 = u*q1 + q0;
52        if ( r0 > 0 ) {
53            u = r1 / r0;
54            r1 = r1 % r0;
55            q1 = u*q0 + q1;
56        }
57    }
58    if ( r0 == 0 )
59        return -(int)q1;
60    else
61        return (int)q0;
62}
Note: See TracBrowser for help on using the repository browser.