mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Fixed "constant exceeds range of float [-Woverflow]" (issue #544)
This commit is contained in:
		| @@ -19,13 +19,14 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") | ||||
| 		-Wformat=2 | ||||
| 		-Winit-self | ||||
| 		-Wmissing-include-dirs | ||||
| 		-Wparentheses | ||||
| 		-Wnon-virtual-dtor | ||||
| 		-Wold-style-cast | ||||
| 		-Woverloaded-virtual | ||||
| 		-Wparentheses | ||||
| 		-Wredundant-decls | ||||
| 		-Wshadow | ||||
| 		-Wsign-promo | ||||
| 		-Wstrict-aliasing | ||||
| 		-Wstrict-overflow=5 | ||||
| 		-Wundef | ||||
| 	) | ||||
|   | ||||
| @@ -10,5 +10,12 @@ add_executable(IntegrationTests | ||||
| 	round_trip.cpp | ||||
| ) | ||||
|  | ||||
| if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") | ||||
| 	target_compile_options(IntegrationTests | ||||
| 		PUBLIC | ||||
| 		-fsingle-precision-constant # issue 544 | ||||
| 	) | ||||
| endif() | ||||
|  | ||||
| target_link_libraries(IntegrationTests catch) | ||||
| add_test(IntegrationTests IntegrationTests) | ||||
|   | ||||
| @@ -8,6 +8,7 @@ | ||||
| add_executable(PolyfillsTests  | ||||
| 	isFloat.cpp | ||||
| 	isInteger.cpp | ||||
| 	normalize.cpp | ||||
| 	parseFloat.cpp | ||||
| 	parseInteger.cpp | ||||
| ) | ||||
|   | ||||
							
								
								
									
										43
									
								
								test/Polyfills/normalize.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								test/Polyfills/normalize.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| // Copyright Benoit Blanchon 2014-2017 | ||||
| // MIT License | ||||
| // | ||||
| // Arduino JSON library | ||||
| // https://bblanchon.github.io/ArduinoJson/ | ||||
| // If you like this project, please add a star! | ||||
|  | ||||
| #include <ArduinoJson/Polyfills/normalize.hpp> | ||||
| #include <catch.hpp> | ||||
|  | ||||
| using namespace ArduinoJson::Polyfills; | ||||
|  | ||||
| TEST_CASE("normalize<double>()") { | ||||
|   SECTION("1.7976931348623157E+308") { | ||||
|     double value = 1.7976931348623157E+308; | ||||
|     int exp = normalize(value); | ||||
|     REQUIRE(value == Approx(1.7976931348623157)); | ||||
|     REQUIRE(exp == 308); | ||||
|   } | ||||
|  | ||||
|   SECTION("4.94065645841247e-324") { | ||||
|     double value = 4.94065645841247e-324; | ||||
|     int exp = normalize(value); | ||||
|     REQUIRE(value == Approx(4.94065645841247)); | ||||
|     REQUIRE(exp == -324); | ||||
|   } | ||||
| } | ||||
|  | ||||
| TEST_CASE("normalize<float>()") { | ||||
|   SECTION("3.4E+38") { | ||||
|     float value = 3.4E+38f; | ||||
|     int exp = normalize(value); | ||||
|     REQUIRE(value == Approx(3.4f)); | ||||
|     REQUIRE(exp == 38); | ||||
|   } | ||||
|  | ||||
|   SECTION("1.17549435e−38") { | ||||
|     float value = 1.17549435e-38f; | ||||
|     int exp = normalize(value); | ||||
|     REQUIRE(value == Approx(1.17549435)); | ||||
|     REQUIRE(exp == -38); | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user