1 /* 2 Copyright (C) 2016-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: dk4maai32.ctr 12 */ 13 14 #ifndef DK4MAAI32_H_INCLUDED 15 /** Avoid multiple inclusions. */ 16 #define DK4MAAI32_H_INCLUDED 1 17 18 19 /** @file dk4maai32.h Operations on int32_t data. 20 21 CRT on Windows: Optional. 22 */ 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 #if DK4_HAVE_STDLIB_H 50 #ifndef DK4_STDLIB_H_INCLUDED 51 #include <stdlib.h> 52 #define DK4_STDLIB_H_INCLUDED 1 53 #endif 54 #endif 55 56 #if DK4_HAVE_SYS_TYPES_H 57 #ifndef DK4_SYS_TYPES_H_INCLUDED 58 #include <sys/types.h> 59 #define DK4_SYS_TYPES_H_INCLUDED 1 60 #endif 61 #endif 62 63 #if DK4_HAVE_STDINT_H 64 #ifndef DK4_STDINT_H_INCLUDED 65 #include <stdint.h> 66 #define DK4_STDINT_H_INCLUDED 1 67 #endif 68 #endif 69 70 #ifndef INT32_MAX 71 #define INT32_MAX ((int32_t)2147483647L) 72 #endif 73 74 #ifndef INT32_MIN 75 #define INT32_MIN (((int32_t)(-2147483647L)) - ((int32_t)1L)) 76 #endif 77 78 79 #ifdef __cplusplus 80 extern "C" { 81 #endif 82 83 /** Addition of int32_t. 84 @param a Left operand. 85 @param b Right operand. 86 @param erp Error report, may be NULL. 87 @return Operation result. 88 89 Error codes: 90 - DK4_E_INVALID_ARGUMENTS<br> 91 if a or b is out of range 92 - DK4_E_MATH_OVERFLOW<br> 93 if a mathematical overfow occured. 94 */ 95 int32_t 96 dk4ma_int32_t_add(int32_t a, int32_t b, dk4_er_t *erp); 97 98 /** Substraction of int32_t. 99 @param a Left operand. 100 @param b Right operand. 101 @param erp Error report, may be NULL. 102 @return Operation result. 103 104 Error codes: 105 - DK4_E_INVALID_ARGUMENTS<br> 106 if a or b is out of range 107 - DK4_E_MATH_OVERFLOW<br> 108 if a mathematical overfow occured. 109 */ 110 int32_t 111 dk4ma_int32_t_sub(int32_t a, int32_t b, dk4_er_t *erp); 112 113 /** Multiplication of int32_t. 114 @param a Left operand. 115 @param b Right operand. 116 @param erp Error report, may be NULL. 117 @return Operation result. 118 119 Error codes: 120 - DK4_E_INVALID_ARGUMENTS<br> 121 if a or b is out of range 122 - DK4_E_MATH_OVERFLOW<br> 123 if a mathematical overfow occured. 124 */ 125 int32_t 126 dk4ma_int32_t_mul(int32_t a, int32_t b, dk4_er_t *erp); 127 128 /** Calculate square value of an int. 129 @param a Value to calculate square for. 130 @param erp Error report, may be NULL. 131 @return Square value. 132 */ 133 int32_t 134 dk4ma_int32_t_sq(int32_t a, dk4_er_t *erp); 135 136 /** Division of int32_t. 137 @param a Left operand. 138 @param b Right operand. 139 @param erp Error report, may be NULL. 140 @return Operation result. 141 142 Error codes: 143 - DK4_E_INVALID_ARGUMENTS<br> 144 if a or b is out of range 145 - DK4_E_MATH_OVERFLOW<br> 146 if a mathematical overfow occured, 147 - DK4_E_MATH_DIVZERO<br> 148 if b is 0. 149 */ 150 int32_t 151 dk4ma_int32_t_div(int32_t a, int32_t b, dk4_er_t *erp); 152 153 /** Absolute value. 154 @param a Argument. 155 @param erp Error report, may be NULL. 156 @return Absolute value of a. 157 158 Error codes: 159 - DK4_E_INVALID_ARGUMENTS<br> 160 if a or b is out of range 161 - DK4_E_MATH_OVERFLOW<br> 162 if a mathematical overfow occured. 163 */ 164 int32_t 165 dk4ma_int32_t_abs(int32_t a, dk4_er_t *erp); 166 167 168 /** Convert dk4_im_t value to int32_t. 169 @param i Value to convert. 170 @param erp Error report, may be NULL. 171 @return Conversion result. 172 173 Error codes: DK4_E_MATH_OVERFLOW. 174 */ 175 int32_t 176 dk4ma_int32_from(dk4_im_t i, dk4_er_t *erp); 177 178 /** Convert double to int32_t. 179 @param d Value to convert. 180 @param erp Error report, may be NULL. 181 @return Conversion result. 182 183 Error codes: DK4_E_OVERFLOW. 184 */ 185 int32_t 186 dk4ma_int32_from_double(double d, dk4_er_t *erp); 187 188 /** Find difference of 2 signed integers, return difference 189 as unsigned integer. 190 @param a One parameter. 191 @param b Other parameter. 192 @return Absolute value of the difference. 193 */ 194 uint32_t 195 dk4ma_int32_difference(int32_t a, int32_t b); 196 197 #ifdef __cplusplus 198 } 199 #endif 200 201 202 203 #endif 204