FloatParts.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright Benoit Blanchon 2014-2017
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://bblanchon.github.io/ArduinoJson/
  6. // If you like this project, please add a star!
  7. #include <ArduinoJson/Serialization/FloatParts.hpp>
  8. #include <catch.hpp>
  9. using namespace ArduinoJson::Internals;
  10. TEST_CASE("FloatParts<double>") {
  11. SECTION("1.7976931348623157E+308") {
  12. FloatParts<double> parts(1.7976931348623157E+308);
  13. REQUIRE(parts.integral == 1);
  14. REQUIRE(parts.decimal == 797693135);
  15. REQUIRE(parts.decimalPlaces == 9);
  16. REQUIRE(parts.exponent == 308);
  17. }
  18. SECTION("4.94065645841247e-324") {
  19. FloatParts<double> parts(4.94065645841247e-324);
  20. REQUIRE(parts.integral == 4);
  21. REQUIRE(parts.decimal == 940656458);
  22. REQUIRE(parts.decimalPlaces == 9);
  23. REQUIRE(parts.exponent == -324);
  24. }
  25. }
  26. TEST_CASE("FloatParts<float>") {
  27. SECTION("3.4E+38") {
  28. FloatParts<float> parts(3.4E+38f);
  29. REQUIRE(parts.integral == 3);
  30. REQUIRE(parts.decimal == 4);
  31. REQUIRE(parts.decimalPlaces == 1);
  32. REQUIRE(parts.exponent == 38);
  33. }
  34. SECTION("1.17549435e−38") {
  35. FloatParts<float> parts(1.17549435e-38f);
  36. REQUIRE(parts.integral == 1);
  37. REQUIRE(parts.decimal == 175494);
  38. REQUIRE(parts.decimalPlaces == 6);
  39. REQUIRE(parts.exponent == -38);
  40. }
  41. }