cf_util.cc
Go to the documentation of this file.
1 /* emacs edit mode for this file is -*- C++ -*- */
2 
3 /**
4  *
5  * @file cf_util.cc
6  *
7  * miscellaneous functions, not necessarily related
8  * to canonical forms.
9  *
10  * Used by: fac_cantzass.cc, gfops.cc
11  *
12 **/
13 
14 
15 #include "config.h"
16 
17 
18 /** int ipower ( int b, int m )
19  *
20  * ipower() - calculate b^m in standard integer arithmetic.
21  *
22  * Note: Beware of overflows.
23  *
24 **/
25 int ipower ( int b, int m )
26 {
27  int prod = 1;
28 
29  while ( m != 0 )
30  {
31  if ( m % 2 != 0 )
32  prod *= b;
33  m /= 2;
34  if ( m != 0 )
35  b *= b;
36  }
37  return prod;
38 }
39 
40 int ilog2 (int a)
41 {
42  int n = -1;
43  while ( a > 0 )
44  {
45  n++;
46  a /=2;
47  }
48  return n;
49 }
50 
51 int igcd( int a, int b )
52 {
53  if ( a < 0 ) a = -a;
54  if ( b < 0 ) b = -b;
55 
56  int c;
57 
58  while ( b != 0 )
59  {
60  c = a % b;
61  a = b;
62  b = c;
63  }
64  return a;
65 }
66 
67 #include<stdio.h>
68 #include<stdlib.h>
69 
70 void factoryError_intern(const char *s)
71 {
72  fputs(s,stderr);
73  abort();
74 }
75 void (*factoryError)(const char *s) = factoryError_intern;
76 
77 
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
int igcd(int a, int b)
Definition: cf_util.cc:51
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
int m
Definition: cfEzgcd.cc:119
int ilog2(int a)
Definition: cf_util.cc:40
int ipower(int b, int m)
int ipower ( int b, int m )
Definition: cf_util.cc:25
fq_nmod_poly_t prod
Definition: facHensel.cc:95
const poly b
Definition: syzextra.cc:213
void factoryError_intern(const char *s)
Definition: cf_util.cc:70
void(* factoryError)(const char *s)
Definition: cf_util.cc:75