diff --git a/backend/common.h b/backend/common.h index 439e4b17..bba695ad 100644 --- a/backend/common.h +++ b/backend/common.h @@ -60,17 +60,21 @@ # if _MSC_VER < 1800 /* ceilf, floorf, roundf (C99) not before MSVC 2013 (C++ 12.0) */ # define ceilf (float) ceil # define floorf (float) floor -# define roundf(arg) ((float) floor((arg) + 0.5f)) +# define roundf (float) round +# define fmodf (float) fmod # if _MSC_VER == 1200 /* VC6 */ # define round(arg) floor((arg) + 0.5f) # endif # endif # pragma warning(disable: 4244) /* conversion from int to float */ -# if _MSC_VER >= 1900 /* MSVC 2015 */ +# if _MSC_VER >= 1800 /* MSVC 2013 */ # pragma warning(disable: 4996) /* function or variable may be unsafe */ # endif #endif +/* Is float integral value? (https://stackoverflow.com/a/40404149/664741) */ +#define isfintf(arg) (fmodf(arg, 1.0f) == 0.0f) + #if (defined(__GNUC__) || defined(__clang__)) && !defined(ZINT_TEST) && !defined(__MINGW32__) # define INTERNAL __attribute__ ((visibility ("hidden"))) #elif defined(ZINT_TEST) diff --git a/backend/output.c b/backend/output.c index b24f9afd..796d4781 100644 --- a/backend/output.c +++ b/backend/output.c @@ -540,7 +540,7 @@ INTERNAL float output_large_bar_height(struct zint_symbol *symbol, int si) { for (i = 0; i < symbol->rows; i++) { if (symbol->row_height[i]) { fixed_height += symbol->row_height[i]; - if (!round_rows && si && symbol->row_height[i] * si != (int) (symbol->row_height[i] * si)) { + if (!round_rows && si && !isfintf(symbol->row_height[i] * si)) { round_rows = 1; } } else { @@ -554,7 +554,7 @@ INTERNAL float output_large_bar_height(struct zint_symbol *symbol, int si) { large_bar_height = 0.01f; /* Token positive value */ symbol->height = large_bar_height * zero_count + fixed_height; } - if (si && large_bar_height * si != (int) (large_bar_height * si)) { + if (si && !isfintf(large_bar_height * si)) { large_bar_height = roundf(large_bar_height * si) / si; symbol->height = large_bar_height * zero_count + fixed_height; } @@ -564,7 +564,7 @@ INTERNAL float output_large_bar_height(struct zint_symbol *symbol, int si) { if (round_rows) { fixed_height = 0.0f; for (i = 0; i < symbol->rows; i++) { - if (symbol->row_height[i] * si != (int) (symbol->row_height[i] * si)) { + if (!isfintf(symbol->row_height[i] * si)) { symbol->row_height[i] = roundf(symbol->row_height[i] * si) / si; } fixed_height += symbol->row_height[i]; diff --git a/backend/raster.c b/backend/raster.c index 0ccb2859..e91ed684 100644 --- a/backend/raster.c +++ b/backend/raster.c @@ -938,7 +938,7 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl scaler = 0.5f; } /* If half-integer scaling, then set integer scaler `si` to avoid scaling at end */ - half_int_scaling = scaler * 2.0f == (int) (scaler * 2.0f); + half_int_scaling = isfintf(scaler * 2.0f); if (half_int_scaling) { si = (int) (scaler * 2.0f); } else { diff --git a/backend/tests/testcommon.h b/backend/tests/testcommon.h index 3e017770..9b292228 100644 --- a/backend/tests/testcommon.h +++ b/backend/tests/testcommon.h @@ -77,7 +77,7 @@ extern int assertionFailed; extern int assertionNum; extern const char *assertionFilename; -#if _MSC_VER == 1200 /* VC6 */ +#if _MSC_VER < 1900 /* MSVC 2015 */ #define testStart(__arg__) (testStartReal("", __arg__)) #else #define testStart(__arg__) (testStartReal(__func__, __arg__)) diff --git a/frontend/main.c b/frontend/main.c index d28dc8d8..20cbdfb6 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -31,7 +31,7 @@ #include #include "../getopt/getopt.h" #include "zint.h" -#if _MSC_VER >= 1900 /* MSVC 2015 */ +#if _MSC_VER >= 1800 /* MSVC 2013 */ #pragma warning(disable: 4996) /* function or variable may be unsafe */ #endif #endif /* _MSC_VER */