diff options
author | Norbert Preining <norbert@preining.info> | 2020-09-20 03:03:26 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2020-09-20 03:03:26 +0000 |
commit | 1f457376b478257b88d4a857f5ec1b6155442dd7 (patch) | |
tree | 2a06a60551dea362cf8cb0cb0ba66c78608717c4 /support/dktools/dk4maaui.ctr | |
parent | ac690ca29ad5bf8a5203a65fd6252f7b564f4727 (diff) |
CTAN sync 202009200303
Diffstat (limited to 'support/dktools/dk4maaui.ctr')
-rw-r--r-- | support/dktools/dk4maaui.ctr | 70 |
1 files changed, 68 insertions, 2 deletions
diff --git a/support/dktools/dk4maaui.ctr b/support/dktools/dk4maaui.ctr index 35a57ce74b..c894815b68 100644 --- a/support/dktools/dk4maaui.ctr +++ b/support/dktools/dk4maaui.ctr @@ -2,7 +2,7 @@ copyright owner = Dirk Krause copyright year = 2015-xxxx -license = bsd +SPDX-License-Identifier: BSD-3-Clause @@ -15,15 +15,27 @@ license = bsd */ #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 @@ -76,11 +88,32 @@ dk4ma_uint_mul(unsigned a, unsigned b, dk4_er_t *erp); UINT_MAX on division by zero (see the ec component of erp). - Error codes: DK4_E_DIVZERO. + Error codes: DK4_E_MATH_DIVZERO. */ unsigned dk4ma_uint_div(unsigned a, unsigned b, dk4_er_t *erp); +/** Convert dk4_um_t value to unsigned. + @param u Value to convert. + @param erp Error report, may be NULL. + @return Conversion result. + + Error codes: DK4_E_MATH_OVERFLOW. +*/ +unsigned +dk4ma_uint_from(dk4_um_t u, dk4_er_t *erp); + + +/** Convert double value to unsigned int. + @param d Value to convert. + @param erp Error report, may be NULL. + @return Conversion result. + + Error codes: DK4_E_OVERFLOW. +*/ +unsigned +dk4ma_uint_from_double(double d, dk4_er_t *erp); + #ifdef __cplusplus } #endif @@ -141,3 +174,36 @@ dk4ma_uint_div(unsigned a, unsigned b, dk4_er_t *erp) } } + + +unsigned +dk4ma_uint_from(dk4_um_t u, dk4_er_t *erp) +{ + if ((dk4_um_t)(UINT_MAX) < u) { + dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); + } + return ((unsigned)u); +} + + + +unsigned +dk4ma_uint_from_double(double d, dk4_er_t *erp) +{ + unsigned back = 0U; + if ((double)(UINT_MAX) < d) { + back = UINT_MAX; + dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); + } + else { + if (0.0 > d) { + dk4error_set_simple_error_code(erp,DK4_E_MATH_OVERFLOW); + } + else { + back = (unsigned)d; + } + } + return back; +} + + |