source: git/factory/cf_util.cc @ bebd13f

fieker-DuValspielwiese
Last change on this file since bebd13f was 16f511, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
Fixed the usage of "config.h" (if defined HAVE_CONFIG_H)
  • Property mode set to 100644
File size: 1.1 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#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif /* HAVE_CONFIG_H */
15
16//{{{ int ipower ( int b, int m )
17//{{{ docu
18//
19// ipower() - calculate b^m in standard integer arithmetic.
20//
21// Note: Beware of overflows.
22//
23//}}}
24int ipower ( int b, int m )
25{
26    int prod = 1;
27
28    while ( m != 0 )
29    {
30        if ( m % 2 != 0 )
31            prod *= b;
32        m /= 2;
33        if ( m != 0 )
34            b *= b;
35    }
36    return prod;
37}
38//}}}
39
40int ilog2 (int a)
41{
42  int n = -1;
43  while ( a > 0 )
44  {
45    n++;
46    a /=2;
47  }
48  return n;
49}
50
51int 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
70void factoryError_intern(const char *s)
71{
72  fputs(s,stderr);
73  abort();
74}
75void (*factoryError)(const char *s) = factoryError_intern;
76
77
Note: See TracBrowser for help on using the repository browser.