spielwiese
Last change
on this file since 756676e was
756676e,
checked in by Reimer Behrends <behrends@…>, 5 years ago
|
Add includes for globaldefs.2
|
-
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 "../factory/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 | **/ |
---|
26 | int 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 | |
---|
41 | int ilog2 (int a) |
---|
42 | { |
---|
43 | int n = -1; |
---|
44 | while ( a > 0 ) |
---|
45 | { |
---|
46 | n++; |
---|
47 | a /=2; |
---|
48 | } |
---|
49 | return n; |
---|
50 | } |
---|
51 | |
---|
52 | int 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 | |
---|
71 | void factoryError_intern(const char *s) |
---|
72 | { |
---|
73 | fputs(s,stderr); |
---|
74 | abort(); |
---|
75 | } |
---|
76 | VAR void (*factoryError)(const char *s) = factoryError_intern; |
---|
77 | |
---|
78 | |
---|
Note: See
TracBrowser
for help on using the repository browser.