Commit f67ee680669fdade639d540df326f48176a3d0f3
1 parent
bec6f387
add implementation of euclidean algorithm and compile with REENTRANT and pthread…
… as this code is ment to be used within threads ... also there is no other thread awareness in it
Showing
8 changed files
with
103 additions
and
3 deletions
include/tr/math.h
0 → 100644
| 1 | +/** | |
| 2 | + * \file | |
| 3 | + * Common reusable definitions. | |
| 4 | + * | |
| 5 | + * \todo All public symbols need to be prefixed to make name clashes | |
| 6 | + * more unlikely. | |
| 7 | + * | |
| 8 | + * \author Georg Hopp | |
| 9 | + * | |
| 10 | + * \copyright | |
| 11 | + * Copyright © 2014 Georg Hopp | |
| 12 | + * | |
| 13 | + * This program is free software: you can redistribute it and/or modify | |
| 14 | + * it under the terms of the GNU General Public License as published by | |
| 15 | + * the Free Software Foundation, either version 3 of the License, or | |
| 16 | + * (at your option) any later version. | |
| 17 | + * | |
| 18 | + * This program is distributed in the hope that it will be useful, | |
| 19 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 21 | + * GNU General Public License for more details. | |
| 22 | + * | |
| 23 | + * You should have received a copy of the GNU General Public License | |
| 24 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 25 | + */ | |
| 26 | + | |
| 27 | +#ifndef __TR_MATH_H__ | |
| 28 | +#define __TR_MATH_H__ | |
| 29 | + | |
| 30 | +#include "tr/commons.h" | |
| 31 | + | |
| 32 | +inline | |
| 33 | +long | |
| 34 | +TR_euklidGcd(register long val1, register long val2) | |
| 35 | +{ | |
| 36 | + register long mod; | |
| 37 | + | |
| 38 | + if(val2 > val1) SWAP_XOR(val1, val2); | |
| 39 | + | |
| 40 | + mod = val1 % val2; | |
| 41 | + while (mod != 0) { | |
| 42 | + val1 = val2; | |
| 43 | + val2 = mod; | |
| 44 | + mod = val1 % val2; | |
| 45 | + } | |
| 46 | + | |
| 47 | + return val2; | |
| 48 | +} | |
| 49 | + | |
| 50 | +inline | |
| 51 | +long | |
| 52 | +TR_lcm(register long val1, register long val2) | |
| 53 | +{ | |
| 54 | + return val1 * val2 / TR_euklidGcd(val1, val2); | |
| 55 | +} | |
| 56 | + | |
| 57 | +#endif // __TR_MATH_H__ | |
| 58 | + | |
| 59 | +// vim: set ts=4 sw=4: | ... | ... |
| 1 | 1 | ACLOCAL_AMFLAGS = -I m4 |
| 2 | 2 | AUTOMAKE_OPTIONS = subdir-objects |
| 3 | 3 | |
| 4 | -AM_CFLAGS += -I../include/ | |
| 4 | +AM_CFLAGS += -I../include/ -std=c99 -DREENTRANT -lpthread | |
| 5 | +AM_LDFLAGS += -lpthread | |
| 5 | 6 | |
| 6 | 7 | TR_CLASS = memory.c \ |
| 7 | 8 | interface.c \ |
| ... | ... | @@ -12,6 +13,7 @@ TR_CLASS = memory.c \ |
| 12 | 13 | print_trace.c \ |
| 13 | 14 | stderr.c \ |
| 14 | 15 | syslog.c \ |
| 16 | + math.c \ | |
| 15 | 17 | sized_data.c \ |
| 16 | 18 | sized_data_set_data.c \ |
| 17 | 19 | i_class.c \ |
| ... | ... | @@ -24,6 +26,6 @@ TR_CLASS = memory.c \ |
| 24 | 26 | lib_LTLIBRARIES = libtrbase.la |
| 25 | 27 | |
| 26 | 28 | libtrbase_la_SOURCES = $(TR_CLASS) |
| 27 | -libtrbase_la_CFLAGS = $(AM_CFLAGS) -lpthread | |
| 28 | -libtrbase_la_LIBADD = | |
| 29 | +libtrbase_la_CFLAGS = $(AM_CFLAGS) | |
| 30 | +libtrbase_la_LIBADD = $(AM_LDFLAGS) | |
| 29 | 31 | libtrbase_la_LDFLAGS = -version-info 1:0:1 | ... | ... |
src/math.c
0 → 100644
| 1 | +/** | |
| 2 | + * \file | |
| 3 | + * Common reusable definitions. | |
| 4 | + * | |
| 5 | + * \todo All public symbols need to be prefixed to make name clashes | |
| 6 | + * more unlikely. | |
| 7 | + * | |
| 8 | + * \author Georg Hopp | |
| 9 | + * | |
| 10 | + * \copyright | |
| 11 | + * Copyright © 2014 Georg Hopp | |
| 12 | + * | |
| 13 | + * This program is free software: you can redistribute it and/or modify | |
| 14 | + * it under the terms of the GNU General Public License as published by | |
| 15 | + * the Free Software Foundation, either version 3 of the License, or | |
| 16 | + * (at your option) any later version. | |
| 17 | + * | |
| 18 | + * This program is distributed in the hope that it will be useful, | |
| 19 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 21 | + * GNU General Public License for more details. | |
| 22 | + * | |
| 23 | + * You should have received a copy of the GNU General Public License | |
| 24 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 25 | + */ | |
| 26 | + | |
| 27 | +#include "tr/math.h" | |
| 28 | + | |
| 29 | +extern inline long TR_euklidGcd(register long, register long); | |
| 30 | +extern inline long TR_lcm(register long, register long); | ... | ... |
Please
register
or
login
to post a comment