BAM
Abstract Machine for Bottom-Up Evaluation with the Push Method
Main Page
Related Pages
Classes
Files
File List
File Members
base
idiv.h
Go to the documentation of this file.
1
// ============================================================================
2
// Project: Deductive Database
3
// Filename: idiv.h
4
// Purpose: Macros for rounded integer division and percent
5
// Last Change: 04.08.2017
6
// Language: C++
7
// EMail: brass@informatik.uni-halle.de
8
// WWW: http://www.informatik.uni-halle.de/~brass/
9
// Address: Feldschloesschen 15, D-06120 Halle (Saale), GERMANY
10
// Copyright: (c) 2015-2017 by Stefan Brass
11
// License: See file "LICENSE" for copying conditions.
12
// Note: There is no warranty at all - this code may contain bugs.
13
// ============================================================================
14
15
22
//=============================================================================
23
// Include File Frame:
24
//=============================================================================
25
26
#ifndef IDIV_INCLUDED
27
#define IDIV_INCLUDED
28
29
30
//=============================================================================
31
// Used Types and Macros:
32
//=============================================================================
33
34
#ifndef VER_INCLUDED
35
#include "../base/ver.h"
36
#endif
37
38
#ifndef CHECK_INCLUDED
39
#include "../base/check.h"
40
#endif
41
42
43
//=============================================================================
44
// Defined Types and Macros:
45
//=============================================================================
46
47
// Note that all macros work only for non-negative numbers.
48
// For negative numbers, C and C++ do not completely prescribe the result
49
// of integer division. It would be more complicated to get a portable result.
50
51
//-----------------------------------------------------------------------------
52
// IDIV_ROUND:
53
//-----------------------------------------------------------------------------
54
61
#define IDIV_ROUND(X,Y) (((X)+(Y)/2)/(Y))
62
63
//-----------------------------------------------------------------------------
64
// IDIV_CEILING:
65
//-----------------------------------------------------------------------------
66
73
#define IDIV_CEILING(X,Y) (((X)+(Y)-1)/(Y))
74
75
//-----------------------------------------------------------------------------
76
// IDIV_WHOLE:
77
//-----------------------------------------------------------------------------
78
85
#define IDIV_WHOLE(X,Y) ((((X)*10+(Y)/2)/(Y))/10)
86
87
//-----------------------------------------------------------------------------
88
// IDIV_TENTH:
89
//-----------------------------------------------------------------------------
90
97
//#define IDIV_TENTH(X,Y) ((((X)*10+(Y)/2)/(Y))%10)
98
#define IDIV_TENTH(X,Y) (((((X)-IDIV_WHOLE((X),(Y))*(Y)) * 10 + (Y)/2)) / (Y))
99
// In this way, we do not have to multiply X by 10,
100
// which is important if X is large (near the integer limit).
101
102
//-----------------------------------------------------------------------------
103
// IDIV_PERCENT:
104
//-----------------------------------------------------------------------------
105
110
#define IDIV_PERCENT(X,Y) (((X)*100+((Y)/2))/(Y))
111
112
113
//=============================================================================
114
// End of Include File:
115
//=============================================================================
116
117
#endif
118
Generated by
1.8.10