source: git/factory/ffops.h @ 02af91

spielwiese
Last change on this file since 02af91 was 02af91, checked in by Rüdiger Stobbe <stobbe@…>, 27 years ago
"Now the functionality to handle prime numbers that are bigger than 2^15. This results in various changes and some new functions. " git-svn-id: file:///usr/local/Singular/svn/trunk@21 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 1.8 KB
Line 
1// emacs edit mode for this file is -*- C++ -*-
2// $Id: ffops.h,v 1.1 1996-06-18 06:57:00 stobbe Exp $
3
4#ifndef INCL_FFOPS_H
5#define INCL_FFOPS_H
6
7/*
8$Log: not supported by cvs2svn $
9Revision 1.0  1996/05/17 10:59:40  stobbe
10Initial revision
11
12*/
13
14#include "cf_globals.h"
15#include "cf_switches.h"
16
17extern int ff_prime;
18extern int ff_halfprime;
19extern short * ff_invtab;
20extern bool ff_big;
21
22int ff_newinv ( const int );
23int ff_biginv ( const int );
24void ff_setprime ( const int );
25
26inline int ff_norm ( const int a )
27{
28    int n = a % ff_prime;
29    if ( n < 0 )
30        return n + ff_prime;
31    else
32        return n;
33}
34
35inline int ff_symmetric( const int a )
36{
37    if ( cf_glob_switches.isOn( SW_SYMMETRIC_FF ) )
38        return ( a > ff_halfprime ) ? a - ff_prime : a;
39    else
40        return a;
41}
42
43inline int ff_longnorm ( const long a )
44{
45    int n = (int)(a % (long)ff_prime);
46    if ( n < 0 )
47        return n + ff_prime;
48    else
49        return n;
50}
51
52inline int ff_bignorm ( const long long int a )
53{
54    int n = (int)(a % (long long int)ff_prime);
55    if ( n < 0 )
56        return n + ff_prime;
57    else
58        return n;
59}
60
61inline int ff_add ( const int a, const int b )
62{
63    return ff_norm( a + b );
64}
65
66inline int ff_sub ( const int a, const int b )
67{
68    return ff_norm( a - b );
69}
70
71inline int ff_neg ( const int a )
72{
73    return ff_norm( -a );
74}
75
76inline int ff_mul ( const int a, const int b )
77{
78    if ( ff_big )
79        return ff_bignorm( (long long int)a * (long long int)b );
80    else
81        return ff_longnorm ( (long)a * (long)b );
82}
83
84inline int ff_inv ( const int a )
85{
86    if ( ff_big )
87        return ff_biginv( a );
88    else {
89        register b;
90        if ( (b = (int)(ff_invtab[a])) )
91            return b;
92        else
93            return ff_newinv( a );
94    }
95   
96}
97
98inline 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 */
Note: See TracBrowser for help on using the repository browser.