Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
241818 views
1
#ifndef _CSTD_INCLUDE
2
#define _CSTD_INCLUDE
3
4
#include "gmp.h"
5
6
/*
7
Copyright 2007 Andrew V. Sutherland
8
9
This file is part of smalljac.
10
11
smalljac is free software: you can redistribute it and/or modify
12
it under the terms of the GNU General Public License as published by
13
the Free Software Foundation, either version 2 of the License, or
14
(at your option) any later version.
15
16
smalljac is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
GNU General Public License for more details.
20
21
You should have received a copy of the GNU General Public License
22
along with smalljac. If not, see <http://www.gnu.org/licenses/>.
23
*/
24
25
// General utility items that potentially could be used by any module
26
27
#define DEBUG_LEVEL 2
28
#define INFO_LEVEL 1
29
#define WARN_LEVEL -1
30
#define ERROR_LEVEL -2
31
#define OUTPUT_LEVEL 0
32
33
int dbg_level;
34
35
#define dbg_setlevel(i) (dbg_level = (i))
36
#define dbg_printf if ( dbg_level >= DEBUG_LEVEL ) gmp_printf
37
#define info_printf if ( dbg_level >= INFO_LEVEL ) gmp_printf
38
#define warn_printf if ( dbg_level >= WARN_LEVEL ) gmp_printf
39
#define err_printf if ( dbg_level >= ERROR_LEVEL ) gmp_printf
40
#define out_printf if ( dbg_level >= OUTPUT_LEVEL ) gmp_printf
41
42
#define delta_msecs(s,t) (1000UL*(t-s)/CLOCKS_PER_SEC)
43
#define delta_nsecs(s,t) (1000000000UL*(t-s)/CLOCKS_PER_SEC) // assumes 64 bit UL
44
#define delta_secs(s,t) ((double)(t-s)/CLOCKS_PER_SEC)
45
#define delta_wall_msecs(w1,w2) (1000*((w2)->tv_sec - (w1)->tv_sec) + ((w2)->tv_usec - (w1)->tv_usec)/1000)
46
47
// Centralized memory allocation to aid debugging.
48
// mem_alloc will never fail (it aborts on errors) and zero-fills all allocated memory.
49
void *mem_alloc (unsigned long bytes);
50
void mem_free (void *ptr);
51
52
#define my_mpz_init(z) { puts ("mpz_init"); mpz_init(z); }
53
#define my_mpz_clear(z) { puts ("mpz_clear"); mpz_clear(z); }
54
55
#endif
56
57