source: git/factory/cf_util.cc @ eebdf2

fieker-DuValspielwiese
Last change on this file since eebdf2 was b52d27, checked in by Martin Lee <martinlee84@…>, 10 years ago
chg: more docu changes
  • 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 "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**/
25int 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
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.