diff --git a/docs/Unity Summary.odt b/docs/Unity Summary.odt index 5000e56..2da4d3d 100644 Binary files a/docs/Unity Summary.odt and b/docs/Unity Summary.odt differ diff --git a/docs/Unity Summary.pdf b/docs/Unity Summary.pdf index 0fced09..c914529 100644 Binary files a/docs/Unity Summary.pdf and b/docs/Unity Summary.pdf differ diff --git a/src/unity.c b/src/unity.c index dc2af66..341fa0e 100644 --- a/src/unity.c +++ b/src/unity.c @@ -44,13 +44,10 @@ const char UnityStrResultsTests[] = " Tests "; const char UnityStrResultsFailures[] = " Failures "; const char UnityStrResultsIgnored[] = " Ignored "; -#ifndef UNITY_EXCLUDE_FLOAT +#ifdef UNITY_FLOAT_NEEDS_ZERO // Dividing by these constants produces +/- infinity. // The rationale is given in UnityAssertFloatIsInf's body. static const _UF f_zero = 0.0f; -#ifndef UNITY_EXCLUDE_DOUBLE -static const _UD d_zero = 0.0; -#endif #endif // compiler-generic print formatting masks @@ -738,29 +735,30 @@ void UnityAssertFloatSpecial(const _UF actual, //We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise case UNITY_FLOAT_IS_INF: case UNITY_FLOAT_IS_NOT_INF: - is_trait = ((1.0f / f_zero) == actual) ? 1 : 0; + is_trait = isinf(actual) & ispos(actual); break; case UNITY_FLOAT_IS_NEG_INF: case UNITY_FLOAT_IS_NOT_NEG_INF: - is_trait = ((-1.0f / f_zero) == actual) ? 1 : 0; + is_trait = isinf(actual) & isneg(actual); break; //NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN. case UNITY_FLOAT_IS_NAN: case UNITY_FLOAT_IS_NOT_NAN: - is_trait = (actual == actual) ? 0 : 1; + is_trait = isnan(actual); break; //A determinate number is non infinite and not NaN. (therefore the opposite of the two above) case UNITY_FLOAT_IS_DET: case UNITY_FLOAT_IS_NOT_DET: - if ( (actual != actual) || ((1.0f / f_zero) == actual) || ((-1.0f / f_zero) == actual) ) + if (isinf(actual) | isnan(actual)) is_trait = 0; else is_trait = 1; break; - default: - ; + + default: + break; } if (is_trait != should_be_trait) @@ -894,35 +892,36 @@ void UnityAssertDoubleSpecial(const _UD actual, UNITY_SKIP_EXECUTION; - switch(style) + switch(style) { //To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly //We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise case UNITY_FLOAT_IS_INF: case UNITY_FLOAT_IS_NOT_INF: - is_trait = ((1.0 / d_zero) == actual) ? 1 : 0; + is_trait = isinf(actual) & ispos(actual); break; case UNITY_FLOAT_IS_NEG_INF: case UNITY_FLOAT_IS_NOT_NEG_INF: - is_trait = ((-1.0 / d_zero) == actual) ? 1 : 0; + is_trait = isinf(actual) & isneg(actual); break; //NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN. case UNITY_FLOAT_IS_NAN: case UNITY_FLOAT_IS_NOT_NAN: - is_trait = (actual == actual) ? 0 : 1; + is_trait = isnan(actual); break; //A determinate number is non infinite and not NaN. (therefore the opposite of the two above) case UNITY_FLOAT_IS_DET: case UNITY_FLOAT_IS_NOT_DET: - if ( (actual != actual) || ((1.0 / d_zero) == actual) || ((-1.0 / d_zero) == actual) ) + if (isinf(actual) | isnan(actual)) is_trait = 0; else is_trait = 1; break; - default: - ; + + default: + break; } if (is_trait != should_be_trait) diff --git a/src/unity_internals.h b/src/unity_internals.h index 97e2ba0..ad815f3 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -36,6 +36,11 @@ //apparently this is not a constant expression: (sizeof(unsigned int *) * 256 - 1) so we have to just let this fall through #endif #endif + +#ifndef UNITY_EXCLUDE_MATH_H +#include +#endif + //------------------------------------------------------- // Guess Widths If Not Specified //------------------------------------------------------- @@ -214,6 +219,23 @@ typedef _US64 _U_SINT; #endif typedef UNITY_FLOAT_TYPE _UF; +#ifndef isinf +#define isinf(n) (((1.0f / f_zero) == n) ? 1 : 0) || (((-1.0f / f_zero) == n) ? 1 : 0) +#define UNITY_FLOAT_NEEDS_ZERO +#endif + +#ifndef isnan +#define isnan(n) ((n != n) ? 1 : 0) +#endif + +#ifndef isneg +#define isneg(n) ((n < 0.0f) ? 1 : 0) +#endif + +#ifndef ispos +#define ispos(n) ((n > 0.0f) ? 1 : 0) +#endif + #endif //------------------------------------------------------- diff --git a/test/targets/clang_file.yml b/test/targets/clang_file.yml new file mode 100644 index 0000000..a14205a --- /dev/null +++ b/test/targets/clang_file.yml @@ -0,0 +1,83 @@ +--- +compiler: + path: clang + source_path: '../src/' + unit_tests_path: &unit_tests_path 'tests/' + build_path: &build_path 'build/' + options: + - '-c' + - '-Wall' + - '-Wextra' + - '-Werror' + - '-Wcast-qual' + - '-Wconversion' + - '-Wdisabled-optimization' + - '-Wformat=2' + - '-Winit-self' + - '-Winline' + - '-Winvalid-pch' + - '-Wmissing-declarations' + - '-Wmissing-include-dirs' + - '-Wmissing-prototypes' + - '-Wnonnull' + - '-Wpacked' + - '-Wpointer-arith' + - '-Wredundant-decls' + - '-Wswitch-default' + - '-Wstrict-aliasing' + - '-Wstrict-overflow=5' + - '-Wuninitialized' + - '-Wunused' + - '-Wunreachable-code' + - '-Wreturn-type' + - '-Wshadow' + - '-Wundef' + - '-Wwrite-strings' + - '-Wno-missing-declarations' + - '-Wno-missing-prototypes' + - '-Wno-nested-externs' + - '-Wno-redundant-decls' + - '-Wno-unused-parameter' + - '-Wno-variadic-macros' + - '-Wbad-function-cast' + - '-fms-extensions' + - '-fno-omit-frame-pointer' + - '-ffloat-store' + - '-fno-common' + - '-fstrict-aliasing' + - '-std=gnu99' + - '-pedantic' + - '-O0' + includes: + prefix: '-I' + items: + - 'src/' + - '../src/' + - *unit_tests_path + defines: + prefix: '-D' + items: + - UNITY_INCLUDE_DOUBLE + - UNITY_SUPPORT_64 + - UNITY_OUTPUT_RESULTS_FILE + object_files: + prefix: '-o' + extension: '.o' + destination: *build_path +linker: + path: gcc + options: + - -lm + - '-m64' + includes: + prefix: '-I' + object_files: + path: *build_path + extension: '.o' + bin_files: + prefix: '-o' + extension: '.exe' + destination: *build_path +colour: true +:unity: + :plugins: [] diff --git a/test/targets/gcc_manual_math.yml b/test/targets/gcc_manual_math.yml new file mode 100644 index 0000000..64ea3f9 --- /dev/null +++ b/test/targets/gcc_manual_math.yml @@ -0,0 +1,46 @@ +compiler: + path: gcc + source_path: '../src/' + unit_tests_path: &unit_tests_path 'tests/' + build_path: &build_path 'build/' + options: + - '-c' + - '-m64' + - '-Wall' + - '-Wno-address' + - '-std=c99' + - '-pedantic' + includes: + prefix: '-I' + items: + - 'src/' + - '../src/' + - *unit_tests_path + defines: + prefix: '-D' + items: + - UNITY_EXCLUDE_MATH_H + - UNITY_INCLUDE_DOUBLE + - UNITY_SUPPORT_TEST_CASES + - UNITY_SUPPORT_64 + object_files: + prefix: '-o' + extension: '.o' + destination: *build_path +linker: + path: gcc + options: + - -lm + - '-m64' + includes: + prefix: '-I' + object_files: + path: *build_path + extension: '.o' + bin_files: + prefix: '-o' + extension: '.exe' + destination: *build_path +colour: true +:unity: + :plugins: []