source: git/factory/cf_util.cc @ 88534e9

spielwiese
Last change on this file since 88534e9 was 88534e9, checked in by Hans Schoenemann <hannes@…>, 4 years ago
fix: factory paths for a sep. factory distribution
  • Property mode set to 100644
File size: 1.0 KB
Line 
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 "globaldefs.h"
16#include "config.h"
17
18
19/** int ipower ( int b, int m )
20 *
21 * ipower() - calculate b^m in standard integer arithmetic.
22 *
23 * Note: Beware of overflows.
24 *
25**/
26int ipower ( int b, int m )
27{
28    int prod = 1;
29
30    while ( m != 0 )
31    {
32        if ( m % 2 != 0 )
33            prod *= b;
34        m /= 2;
35        if ( m != 0 )
36            b *= b;
37    }
38    return prod;
39}
40
41int ilog2 (int a)
42{
43  int n = -1;
44  while ( a > 0 )
45  {
46    n++;
47    a /=2;
48  }
49  return n;
50}
51
52int igcd( int a, int b )
53{
54    if ( a < 0 ) a = -a;
55    if ( b < 0 ) b = -b;
56
57    int c;
58
59    while ( b != 0 )
60    {
61        c = a % b;
62        a = b;
63        b = c;
64    }
65    return a;
66}
67
68#include<stdio.h>
69#include<stdlib.h>
70
71void factoryError_intern(const char *s)
72{
73  fputs(s,stderr);
74  abort();
75}
76VAR void (*factoryError)(const char *s) = factoryError_intern;
77
78
Note: See TracBrowser for help on using the repository browser.