source: git/factory/cf_util.cc @ e4fe2b

spielwiese
Last change on this file since e4fe2b was e4fe2b, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
FIX: Fixed huge BUG in cf_gmp.h CHG: starting to cleanup factory
  • Property mode set to 100644
File size: 872 bytes
RevLine 
[493c477]1/* emacs edit mode for this file is -*- C++ -*- */
[341696]2/* $Id$ */
[2dd068]3
[26186f]4//{{{ docu
5//
6// cf_util.cc - miscellaneous functions, not necessarily related
7//   to canonical forms.
8//
[b07fd0]9// Used by: fac_cantzass.cc, gfops.cc
10//
[26186f]11//}}}
[b973c0]12
[e4fe2b]13#include "config.h"
[b973c0]14
[26186f]15//{{{ int ipower ( int b, int m )
16//{{{ docu
17//
18// ipower() - calculate b^m in standard integer arithmetic.
19//
20// Note: Beware of overflows.
21//
22//}}}
[d4932a]23int ipower ( int b, int m )
[2dd068]24{
25    int prod = 1;
26
[9c115e1]27    while ( m != 0 )
28    {
[d4932a]29        if ( m % 2 != 0 )
30            prod *= b;
31        m /= 2;
32        if ( m != 0 )
33            b *= b;
[2dd068]34    }
35    return prod;
36}
[26186f]37//}}}
[d4932a]38
39int ilog2 (int a)
40{
41  int n = -1;
[408edb]42  while ( a > 0 )
[d4932a]43  {
44    n++;
45    a /=2;
46  }
47  return n;
48}
[a41f4b6]49
50#include<stdio.h>
[52c31f]51#include<stdlib.h>
[a41f4b6]52
[52c31f]53void factoryError_intern(const char *s)
[a41f4b6]54{
[c1b9927]55  fputs(s,stderr);
[52c31f]56  abort();
[a41f4b6]57}
[1d6815]58void (*factoryError)(const char *s) = factoryError_intern;
[52c31f]59
[a41f4b6]60
Note: See TracBrowser for help on using the repository browser.