1 /*
2 Copyright (C) 2015-2021, Dirk Krause
3 SPDX-License-Identifier: BSD-3-Clause
4 */
5 
6 /*
7 	WARNING: This file was generated by the dkct program (see
8 	http://dktools.sourceforge.net/ for details).
9 	Changes you make here will be lost if dkct is run again!
10 	You should modify the original source and run dkct on it.
11 	Original source: dk4maai.ctr
12 */
13 
14 #ifndef DK4MAAI_H_INCLUDED
15 /** Avoid multiple inclusions. */
16 #define DK4MAAI_H_INCLUDED 1
17 
18 
19 /**	@file
20 	Arithmetic operations on int.
21 
22 	CRT on Windows: Optional.
23 */
24 
25 #ifndef DK4CONF_H_INCLUDED
26 #if DK4_BUILDING_DKTOOLS4
27 #include "dk4conf.h"
28 #else
29 #include <dktools-4/dk4conf.h>
30 #endif
31 #endif
32 
33 #ifndef DK4TYPES_H_INCLUDED
34 #if DK4_BUILDING_DKTOOLS4
35 #include <libdk4base/dk4types.h>
36 #else
37 #include <dktools-4/dk4types.h>
38 #endif
39 #endif
40 
41 #ifndef DK4ERROR_H_INCLUDED
42 #if DK4_BUILDING_DKTOOLS4
43 #include <libdk4base/dk4error.h>
44 #else
45 #include <dktools-4/dk4error.h>
46 #endif
47 #endif
48 
49 
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 /**	Absolute value.
56 	@param	a	Operand.
57 	@param	erp	Error report, may be NULL.
58 	@return	Result on success, INT_MAX if a is INT_MIN
59 	(overflow is reported in erp).
60 
61 	Error codes: DK4_E_OVERFLOW.
62 */
63 int
64 dk4ma_int_abs(int a, dk4_er_t *erp);
65 
66 /**	Addition.
67 	@param	a	Left operand.
68 	@param	b	Right operand.
69 	@param	erp	Error report, may be NULL.
70 	@return	Result on success, least significant result bits
71 	on overflow (see ec component of erp).
72 
73 	Error codes: DK4_E_OVERFLOW.
74 */
75 int
76 dk4ma_int_add(int a, int b, dk4_er_t *erp);
77 
78 /**	Subtraction.
79 	@param	a	Left operand.
80 	@param	b	Right operand.
81 	@param	erp	Error report, may be NULL.
82 	@return	Result on success, least significant result bits
83 	on overflow (see ec component of erp).
84 
85 	Error codes: DK4_E_OVERFLOW.
86 */
87 int
88 dk4ma_int_sub(int a, int b, dk4_er_t *erp);
89 
90 /**	Multiplication.
91 	@param	a	Left factor.
92 	@param	b	right factor.
93 	@param	erp	Error report, may be NULL.
94 	@return	Result on success, least significant
95 	bits on overflow (see ec component of erp).
96 
97 	Error codes: DK4_E_OVERFLOW.
98 */
99 int
100 dk4ma_int_mul(int a, int b, dk4_er_t *erp);
101 
102 /**	Division.
103 	@param	a	Counter (left operand).
104 	@param	b	Denominator (right operand).
105 	@param	erp	Error report, may be NULL.
106 	@return	Division result on success,
107 	INT_MIN, INT_MAX, or 0 on division by zero or overflow
108 	(see the ec component of erp).
109 
110 	Error codes: DK4_E_OVERFLOW, DK4_E_DIVZERO.
111 */
112 int
113 dk4ma_int_div(int a, int b, dk4_er_t *erp);
114 
115 /**	Convert dk4_im_t value to int.
116 	@param	i	Value to convert.
117 	@param	erp	Error report, may be NULL.
118 	@return	Conversion result.
119 
120 	Error codes: DK4_E_OVERFLOW.
121 */
122 int
123 dk4ma_int_from(dk4_im_t i, dk4_er_t *erp);
124 
125 /**	Convert double value to int.
126 	@param	d	Value to convert.
127 	@param	erp	Error report, may be NULL.
128 	@return	Conversion result.
129 
130 	Error codes: DK4_E_OVERFLOW.
131 */
132 int
133 dk4ma_int_from_double(double d, dk4_er_t *erp);
134 
135 #ifdef __cplusplus
136 }
137 #endif
138 
139 
140 
141 #endif
142