diff options
author | Norbert Preining <norbert@preining.info> | 2020-10-12 03:04:00 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2020-10-12 03:04:00 +0000 |
commit | 0ce40abb18ec02ec6fd6bcc5f21612c88daa7578 (patch) | |
tree | 416289fe1448873fd8ca33051f50ad85bffa8aaa /support/dktools/dk4maal.ctr | |
parent | fdb18507cd80dc17f5a5256153d34668b4f4e61c (diff) |
CTAN sync 202010120303
Diffstat (limited to 'support/dktools/dk4maal.ctr')
-rw-r--r-- | support/dktools/dk4maal.ctr | 292 |
1 files changed, 0 insertions, 292 deletions
diff --git a/support/dktools/dk4maal.ctr b/support/dktools/dk4maal.ctr deleted file mode 100644 index 28f2e0b44e..0000000000 --- a/support/dktools/dk4maal.ctr +++ /dev/null @@ -1,292 +0,0 @@ -%% options - -copyright owner = Dirk Krause -copyright year = 2015-xxxx -SPDX-License-Identifier: BSD-3-Clause - - -%% header - -/** @file - Arithmetic operations on 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 - -/** Absolute value. - @param a Operand. - @param erp Error report, may be NULL. - @return Result on success, LONG_MAX if a is LONG_MIN - (overflow is reported in erp). - - Error codes: DK4_E_OVERFLOW. -*/ -long -dk4ma_long_abs(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 -dk4ma_long_add(long a, 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 -dk4ma_long_sub(long a, 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 -dk4ma_long_mul(long a, 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, - LONG_MIN, LONG_MAX, or 0 on division by zero or overflow - (see the ec component of erp). - - Error codes: DK4_E_OVERFLOW, DK4_E_DIVZERO. -*/ -long -dk4ma_long_div(long a, long b, dk4_er_t *erp); - -/** Convert dk4_im_t value to long. - @param i Value to convert. - @param erp Error report, may be NULL. - @return Conversion result. - - Error codes: DK4_E_OVERFLOW. -*/ -long -dk4ma_long_from(dk4_im_t i, dk4_er_t *erp); - -/** Convert double to long. - @param d Value to convert. - @param erp Error report, may be NULL. - @return Conversion result. - - Error codes: DK4_E_OVERFLOW. -*/ -long -dk4ma_long_from_double(double d, dk4_er_t *erp); - -#ifdef __cplusplus -} -#endif - - -%% module - -#include "dk4conf.h" -#include "dk4types.h" -#include "dk4error.h" -#include "dk4numco.h" -#include "dk4maal.h" - - - -long -dk4ma_long_abs(long a, dk4_er_t *erp) -{ - if (LONG_MIN == a) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - return ((0L <= a) ? a : ((LONG_MIN == a) ? LONG_MAX : (0L - a))); -} - - - -long -dk4ma_long_add(long a, long b, dk4_er_t *erp) -{ - if ((0L < a) && (0L < b)) { - if ((LONG_MAX - a) < b) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } else { - if ((0L > a) && (0L > b)) { - if (LONG_MIN == a) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } else { - if ((LONG_MIN - a) > b) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } - } - } - return (a + b); -} - - - -long -dk4ma_long_sub(long a, long b, dk4_er_t *erp) -{ - if ((0L < a) && (0L > b)) { - if ((LONG_MAX + b) < a) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } else { - if ((0L > a) && (0L < b)) { - if ((LONG_MIN + b) > a) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } - } - return (a - b); -} - - - -long -dk4ma_long_mul(long a, long b, dk4_er_t *erp) -{ - if ((0L != a) && (0L != b)) { - if (LONG_MIN == a) { - if (1L != b) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } else { - if (LONG_MIN == b) { - if (1L != a) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } else { - if (0L < a) { - if (0L < b) { - if ((LONG_MAX / a) < b) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } else { - if ((LONG_MIN / a) > b) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } - } else { - if (0L < b) { - if ((LONG_MIN / b) > a) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } else { - if ((LONG_MAX / (0L - a)) < (0L - b)) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - } - } - } - } - } - return (a * b); -} - - - -long -dk4ma_long_div(long a, long b, dk4_er_t *erp) -{ - long back = 0; - if (0L != b) { - if ((LONG_MIN == a) && (-1L == b)) { - back = LONG_MAX; - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } else { - back = a / b; - } - } else { - if (0L < a) { - back = LONG_MAX; - } else { - if (0L > a) { - back = LONG_MIN; - } - } - dk4error_set_simple_error_code(erp, DK4_E_MATH_DIVZERO); - } - return back; -} - - - -long -dk4ma_long_from(dk4_im_t i, dk4_er_t *erp) -{ - if (((dk4_im_t)(LONG_MAX) < i) || ((dk4_im_t)(LONG_MIN) > i)) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - } - return ((long)i); -} - - - -long -dk4ma_long_from_double(double d, dk4_er_t *erp) -{ - long back = 0L; - if ((double)(LONG_MIN) > d) { - dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); - back = LONG_MIN; - } - else { - if ((double)(LONG_MAX) < d) { - dk4error_set_simple_error_code(erp,DK4_E_MATH_OVERFLOW); - back = LONG_MAX; - } - else { - back = (long)d; - } - } - return back; -} |