source: git/factory/cf_util.cc @ 8a30b1

spielwiese
Last change on this file since 8a30b1 was 362fc67, checked in by Martin Lee <martinlee84@…>, 12 years ago
chg: remove $Id$
  • Property mode set to 100644
File size: 1.0 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2
3//{{{ docu
4//
5// cf_util.cc - miscellaneous functions, not necessarily related
6//   to canonical forms.
7//
8// Used by: fac_cantzass.cc, gfops.cc
9//
10//}}}
11
12#include "config.h"
13
14//{{{ int ipower ( int b, int m )
15//{{{ docu
16//
17// ipower() - calculate b^m in standard integer arithmetic.
18//
19// Note: Beware of overflows.
20//
21//}}}
22int ipower ( int b, int m )
23{
24    int prod = 1;
25
26    while ( m != 0 )
27    {
28        if ( m % 2 != 0 )
29            prod *= b;
30        m /= 2;
31        if ( m != 0 )
32            b *= b;
33    }
34    return prod;
35}
36//}}}
37
38int ilog2 (int a)
39{
40  int n = -1;
41  while ( a > 0 )
42  {
43    n++;
44    a /=2;
45  }
46  return n;
47}
48
49int igcd( int a, int b )
50{
51    if ( a < 0 ) a = -a;
52    if ( b < 0 ) b = -b;
53
54    int c;
55
56    while ( b != 0 )
57    {
58        c = a % b;
59        a = b;
60        b = c;
61    }
62    return a;
63}
64
65#include<stdio.h>
66#include<stdlib.h>
67
68void factoryError_intern(const char *s)
69{
70  fputs(s,stderr);
71  abort();
72}
73void (*factoryError)(const char *s) = factoryError_intern;
74
75
Note: See TracBrowser for help on using the repository browser.