diff options
Diffstat (limited to 'support/dktools/dk4maall.ctr')
-rw-r--r-- | support/dktools/dk4maall.ctr | 302 |
1 files changed, 0 insertions, 302 deletions
diff --git a/support/dktools/dk4maall.ctr b/support/dktools/dk4maall.ctr deleted file mode 100644 index 24fb4d1b97..0000000000 --- a/support/dktools/dk4maall.ctr +++ /dev/null @@ -1,302 +0,0 @@ -%% options - -copyright owner = Dirk Krause -copyright year = 2015-xxxx -SPDX-License-Identifier: BSD-3-Clause - - -%% header - -/** @file - Arithmetic operations on long long. - - CRT on Windows: Optional. -*/ - -#ifndef DK4CONF_H_INCLUDED -#if DK4_BUILDING_DKTOOLS4 -#include "dk4conf.h" -#else -#include <dktools-4/dk4conf.h> -#endif -#endif - -#ifndef DK4TYPES_H_INCLUDED -#if DK4_BUILDING_DKTOOLS4 -#include "dk4types.h" -#else -#include <dktools-4/dk4types.h> -#endif -#endif - -#ifndef DK4ERROR_H_INCLUDED -#if DK4_BUILDING_DKTOOLS4 -#include "dk4error.h" -#else -#include <dktools-4/dk4error.h> -#endif -#endif - - - -#ifdef __cplusplus -extern "C" { -#endif - -#if DK4_HAVE_LONG_LONG - -/** Absolute value. - @param a Operand. - @param erp Error report, may be NULL. - @return Result on success, LLONG_MAX if a is LLONG_MIN - (overflow is reported in erp). - - Error codes: DK4_E_OVERFLOW. -*/ -long long -dk4ma_ll_abs(long long a, dk4_er_t *erp); - -/** Addition. - @param a Left operand. - @param b Right operand. - @param erp Error report, may be NULL. - @return Result on success, least significant result bits - on overflow (see ec component of erp). - - Error codes: DK4_E_OVERFLOW. -*/ -long long -dk4ma_ll_add(long long a, long long b, dk4_er_t *erp); - -/** Subtraction. - @param a Left operand. - @param b Right operand. - @param erp Error report, may be NULL. - @return Result on success, least significant result bits - on overflow (see ec component of erp). - - Error codes: DK4_E_OVERFLOW. -*/ -long long -dk4ma_ll_sub(long long a, long long b, dk4_er_t *erp); - -/** Multiplication. - @param a Left factor. - @param b right factor. - @param erp Error report, may be NULL. - @return Result on success, least significant - bits on overflow (see ec component of erp). - - Error codes: DK4_E_OVERFLOW. -*/ -long long -dk4ma_ll_mul(long long a, long long b, dk4_er_t *erp); - -/** Division. - @param a Counter (left operand). - @param b Denominator (right operand). - @param erp Error report, may be NULL. - @return Division result on success, - LLONG_MIN, LLONG_MAX, or 0 on division by zero or overflow - (see the ec component of erp). - - Error codes: DK4_E_OVERFLOW, DK4_E_DIVZERO. -*/ -long long -dk4ma_ll_div(long long a, long long b, dk4_er_t *erp); - -/** Convert dk4_im_t value to long long. - @param i Value to convert. - @param erp Error report, may be NULL. - @return Conversion result. - - Error codes: DK4_E_OVERFLOW. -*/ -long long -dk4ma_ll_from(dk4_im_t i, dk4_er_t *erp); - -/** Convert double to signed char. - @param d Value to convert. - @param erp Error report, may be NULL. - @return Conversion result. - - Error codes: DK4_E_OVERFLOW. -*/ -long long -dk4ma_ll_from_double(double d, dk4_er_t *erp); - -#endif - -#ifdef __cplusplus -} -#endif - - -%% module - -#include "dk4conf.h" -#include "dk4types.h" -#include "dk4error.h" -#include "dk4numco.h" -#include "dk4maall.h" - - -#if DK4_HAVE_LONG_LONG - -long long -dk4ma_ll_abs(long long a, dk4_er_t *erp) -{ - if (LLONG_MIN == a) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - return ((0LL <= a) ? a : ((LLONG_MIN == a) ? LLONG_MAX : (0LL - a))); -} - - - -long long -dk4ma_ll_add(long long a, long long b, dk4_er_t *erp) -{ - if ((0LL < a) && (0LL < b)) { - if ((LLONG_MAX - a) < b) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } else { - if ((0LL > a) && (0LL > b)) { - if (LLONG_MIN == a) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } else { - if ((LLONG_MIN - a) > b) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } - } - } - return (a + b); -} - - - -long long -dk4ma_ll_sub(long long a, long long b, dk4_er_t *erp) -{ - if ((0LL < a) && (0LL > b)) { - if ((LLONG_MAX + b) < a) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } else { - if ((0LL > a) && (0LL < b)) { - if ((LLONG_MIN + b) > a) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } - } - return (a - b); -} - - - -long long -dk4ma_ll_mul(long long a, long long b, dk4_er_t *erp) -{ - if ((0LL != a) && (0LL != b)) { - if (LLONG_MIN == a) { - if (1LL != b) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } else { - if (LLONG_MIN == b) { - if (1LL != a) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } else { - if (0LL < a) { - if (0LL < b) { - if ((LLONG_MAX / a) < b) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } else { - if ((LLONG_MIN / a) > b) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } - } else { - if (0LL < b) { - if ((LLONG_MIN / b) > a) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } else { - if ((LLONG_MAX / (0LL - a)) < (0LL - b)) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } - } - } - } - } - return (a * b); -} - - - -long long -dk4ma_ll_div(long long a, long long b, dk4_er_t *erp) -{ - long long back = 0; - if (0LL != b) { - if ((LLONG_MIN == a) && (-1LL == b)) { - back = LLONG_MAX; - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } else { - back = a / b; - } - } else { - if (0LL < a) { - back = LLONG_MAX; - } else { - if (0LL > a) { - back = LLONG_MIN; - } - } - dk4error_set_simple_error_code(erp, DK4_E_MATH_DIVZERO); - } - return back; -} - - - -long long -dk4ma_ll_from(dk4_im_t i, dk4_er_t *erp) -{ - if (((dk4_im_t)(LLONG_MAX) < i) || ((dk4_im_t)(LLONG_MIN) > i)) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - return ((long long)i); -} - - - -long long -dk4ma_ll_from_double(double d, dk4_er_t *erp) -{ - long long back = 0LL; - if ((double)(LLONG_MIN) > d) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - back = LLONG_MIN; - } - else { - if ((double)(LLONG_MAX) < d) { - dk4error_set_simple_error_code(erp,DK4_E_MATH_OVERFLOW); - back = LLONG_MAX; - } - else { - back = (long long)d; - } - } - return back; -} - - - -#endif - |