source: git/factory/ffops.h @ a70441f

spielwiese
Last change on this file since a70441f was a70441f, checked in by Olaf Bachmann <obachman@…>, 24 years ago
Windows and gcc 2.95 porting git-svn-id: file:///usr/local/Singular/svn/trunk@4273 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 1.7 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2/* $Id: ffops.h,v 1.7 2000-04-27 10:07:30 obachman Exp $ */
3
4#ifndef INCL_FFOPS_H
5#define INCL_FFOPS_H
6
7#include <config.h>
8
9#include "cf_globals.h"
10
11extern int ff_prime;
12extern int ff_halfprime;
13extern short * ff_invtab;
14extern bool ff_big;
15
16int ff_newinv ( const int );
17int ff_biginv ( const int );
18void ff_setprime ( const int );
19
20inline int ff_norm ( const int a )
21{
22    int n = a % ff_prime;
23    if ( n < 0 )
24        return n + ff_prime;
25    else
26        return n;
27}
28
29inline int ff_symmetric( const int a )
30{
31    if ( cf_glob_switches.isOn( SW_SYMMETRIC_FF ) )
32        return ( a > ff_halfprime ) ? a - ff_prime : a;
33    else
34        return a;
35}
36
37inline int ff_longnorm ( const long a )
38{
39    int n = (int)(a % (long)ff_prime);
40    if ( n < 0 )
41        return n + ff_prime;
42    else
43        return n;
44}
45
46#ifndef __MWERKS__
47inline int ff_bignorm ( const INT64 a )
48{
49    int n = (int)(a % (INT64)ff_prime);
50    if ( n < 0 )
51        return n + ff_prime;
52    else
53        return n;
54}
55#endif
56
57inline int ff_add ( const int a, const int b )
58{
59    return ff_norm( a + b );
60}
61
62inline int ff_sub ( const int a, const int b )
63{
64    return ff_norm( a - b );
65}
66
67inline int ff_neg ( const int a )
68{
69    return ff_norm( -a );
70}
71
72#ifdef __MWERKS__
73int ff_mul ( const int a, const int b );
74#else
75inline int ff_mul ( const int a, const int b )
76{
77    if ( ff_big )
78        return ff_bignorm( (INT64)a * (INT64)b );
79    else
80        return ff_longnorm ( (long)a * (long)b );
81}
82#endif
83
84inline int ff_inv ( const int a )
85{
86    if ( ff_big )
87        return ff_biginv( a );
88    else {
89        register int 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.