diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index 4811d4e3a..ae1445f49 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -17552,44 +17552,6 @@ int32 func_pos(int32 ignore) { return write_page->cursor_x; } -double func_log(double value) { - if (value <= 0) { - error(5); - return 0; - } - return std::log(value); -} - -// FIX -double func_fix_double(double value) { - if (value < 0) - return std::ceil(value); - else - return std::floor(value); -} -long double func_fix_float(long double value) { - if (value < 0) - return std::ceil(value); - else - return std::floor(value); -} - -// EXP -double func_exp_single(double value) { - if (value <= 88.02969) { - return std::exp(value); - } - error(6); - return 0; -} -long double func_exp_float(long double value) { - if (value <= 709.782712893) { - return std::exp(value); - } - error(6); - return 0; -} - int32 sleep_break = 0; void sub_sleep(int32 seconds, int32 passed) { diff --git a/internal/c/libqb/build.mk b/internal/c/libqb/build.mk index ca27bfeae..a09f384cf 100644 --- a/internal/c/libqb/build.mk +++ b/internal/c/libqb/build.mk @@ -9,6 +9,7 @@ libqb-objs-y += $(PATH_LIBQB)/src/error_handle.o libqb-objs-y += $(PATH_LIBQB)/src/gfs.o libqb-objs-y += $(PATH_LIBQB)/src/qblist.o libqb-objs-y += $(PATH_LIBQB)/src/mem.o +libqb-objs-y += $(PATH_LIBQB)/src/math.o libqb-objs-y += $(PATH_LIBQB)/src/rounding.o libqb-objs-y += $(PATH_LIBQB)/src/qbs.o libqb-objs-y += $(PATH_LIBQB)/src/qbs_str.o diff --git a/internal/c/libqb/include/qbmath.h b/internal/c/libqb/include/qbmath.h new file mode 100644 index 000000000..3b7bdc38a --- /dev/null +++ b/internal/c/libqb/include/qbmath.h @@ -0,0 +1,123 @@ +#pragma once + +#include +#include +#include + +double func_log(double value); +double func_fix_double(double value); +long double func_fix_float(long double value); +double func_exp_single(double value); +long double func_exp_float(long double value); + +// force abs to return floating point numbers correctly +static inline double func_abs(double d) { return std::fabs(d); } +static inline long double func_abs(long double d) { return std::fabs(d); } +static inline float func_abs(float d) { return std::fabs(d); } + +static inline uint8_t func_abs(uint8_t d) { return d; } +static inline uint16_t func_abs(uint16_t d) { return d; } +static inline uint32_t func_abs(uint32_t d) { return d; } +static inline uint64_t func_abs(uint64_t d) { return d; } +static inline int8_t func_abs(int8_t d) { return std::abs(d); } +static inline int16_t func_abs(int16_t d) { return std::abs(d); } +static inline int32_t func_abs(int32_t d) { return std::abs(d); } +static inline int64_t func_abs(int64_t d) { return std::llabs(d); } + +static inline int32_t func_sgn(uint8_t v) { + if (v) + return 1; + else + return 0; +} + +static inline int32_t func_sgn(int8_t v) { + if (v) { + if (v > 0) + return 1; + else + return -1; + } + return 0; +} + +static inline int32_t func_sgn(uint16_t v) { + if (v) + return 1; + else + return 0; +} + +static inline int32_t func_sgn(int16_t v) { + if (v) { + if (v > 0) + return 1; + else + return -1; + } + return 0; +} + +static inline int32_t func_sgn(uint32_t v) { + if (v) + return 1; + else + return 0; +} + +static inline int32_t func_sgn(int32_t v) { + if (v) { + if (v > 0) + return 1; + else + return -1; + } + return 0; +} + +static inline int32_t func_sgn(uint64_t v) { + if (v) + return 1; + else + return 0; +} + +static inline int32_t func_sgn(int64_t v) { + if (v) { + if (v > 0) + return 1; + else + return -1; + } + return 0; +} + +static inline int32_t func_sgn(float v) { + if (v) { + if (v > 0) + return 1; + else + return -1; + } + return 0; +} + +static inline int32_t func_sgn(double v) { + if (v) { + if (v > 0) + return 1; + else + return -1; + } + return 0; +} + +static inline int32_t func_sgn(long double v) { + if (v) { + if (v > 0) + return 1; + else + return -1; + } + return 0; +} diff --git a/internal/c/libqb/src/math.cpp b/internal/c/libqb/src/math.cpp new file mode 100644 index 000000000..66a103c25 --- /dev/null +++ b/internal/c/libqb/src/math.cpp @@ -0,0 +1,47 @@ + +#include "libqb-common.h" + +#include + +#include "error_handle.h" +#include "qbmath.h" + +double func_log(double value) { + if (value <= 0) { + error(5); + return 0; + } + return std::log(value); +} + +// FIX +double func_fix_double(double value) { + if (value < 0) + return std::ceil(value); + else + return std::floor(value); +} + +long double func_fix_float(long double value) { + if (value < 0) + return std::ceil(value); + else + return std::floor(value); +} + +// EXP +double func_exp_single(double value) { + if (value <= 88.02969) { + return std::exp(value); + } + error(6); + return 0; +} + +long double func_exp_float(long double value) { + if (value <= 709.782712893) { + return std::exp(value); + } + error(6); + return 0; +} diff --git a/internal/c/qbx.cpp b/internal/c/qbx.cpp index ceb1a5efa..ba156d0fb 100755 --- a/internal/c/qbx.cpp +++ b/internal/c/qbx.cpp @@ -10,6 +10,7 @@ #include "font.h" #include "gui.h" #include "image.h" +#include "qbmath.h" #include "qbs.h" #include "qbs-mk-cv.h" #include "error_handle.h" @@ -372,11 +373,6 @@ extern void sub_graphics_put(float x1f, float y1f, void *element, int32 option, uint32 mask, int32 passed); extern int32 func_csrlin(); extern int32 func_pos(int32 ignore); -extern double func_log(double value); -extern double func_fix_double(double value); -extern long double func_fix_float(long double value); -extern double func_exp_single(double value); -extern long double func_exp_float(long double value); extern void sub_sleep(int32 seconds, int32 passed); extern qbs *func__bin(int64 value, int32 neg_bits); extern qbs *func__bin_float(long double value); @@ -387,18 +383,6 @@ extern qbs *func_hex_float(long double value); extern ptrszint func_lbound(ptrszint *array, int32 index, int32 num_indexes); extern ptrszint func_ubound(ptrszint *array, int32 index, int32 num_indexes); -extern int32 func_sgn(uint8 v); -extern int32 func_sgn(int8 v); -extern int32 func_sgn(uint16 v); -extern int32 func_sgn(int16 v); -extern int32 func_sgn(uint32 v); -extern int32 func_sgn(int32 v); -extern int32 func_sgn(uint64 v); -extern int32 func_sgn(int64 v); -extern int32 func_sgn(float v); -extern int32 func_sgn(double v); -extern int32 func_sgn(long double v); - extern int32 func_inp(int32 port); extern void sub_wait(int32 port, int32 andexpression, int32 xorexpression, int32 passed); @@ -645,19 +629,6 @@ void swap_block(void *a, void *b, uint32 bytes) { } -// force abs to return floating point numbers correctly -inline double func_abs(double d) { return std::fabs(d); } -inline long double func_abs(long double d) { return std::fabs(d); } -inline float func_abs(float d) { return std::fabs(d); } - -inline uint8 func_abs(uint8 d) { return d; } -inline uint16 func_abs(uint16 d) { return d; } -inline uint32 func_abs(uint32 d) { return d; } -inline uint64 func_abs(uint64 d) { return d; } -inline int8 func_abs(int8 d) { return std::abs(d); } -inline int16 func_abs(int16 d) { return std::abs(d); } -inline int32 func_abs(int32 d) { return std::abs(d); } -inline int64 func_abs(int64 d) { return std::llabs(d); } extern int32 disableEvents;