FloatParts.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2019
  3. // MIT License
  4. #include <ArduinoJson/Numbers/FloatParts.hpp>
  5. #include <catch.hpp>
  6. using namespace ARDUINOJSON_NAMESPACE;
  7. TEST_CASE("FloatParts<double>") {
  8. SECTION("1.7976931348623157E+308") {
  9. FloatParts<double> parts(1.7976931348623157E+308);
  10. REQUIRE(parts.integral == 1);
  11. REQUIRE(parts.decimal == 797693135);
  12. REQUIRE(parts.decimalPlaces == 9);
  13. REQUIRE(parts.exponent == 308);
  14. }
  15. SECTION("4.94065645841247e-324") {
  16. FloatParts<double> parts(4.94065645841247e-324);
  17. REQUIRE(parts.integral == 4);
  18. REQUIRE(parts.decimal == 940656458);
  19. REQUIRE(parts.decimalPlaces == 9);
  20. REQUIRE(parts.exponent == -324);
  21. }
  22. }
  23. TEST_CASE("FloatParts<float>") {
  24. SECTION("3.4E+38") {
  25. FloatParts<float> parts(3.4E+38f);
  26. REQUIRE(parts.integral == 3);
  27. REQUIRE(parts.decimal == 4);
  28. REQUIRE(parts.decimalPlaces == 1);
  29. REQUIRE(parts.exponent == 38);
  30. }
  31. SECTION("1.17549435e−38") {
  32. FloatParts<float> parts(1.17549435e-38f);
  33. REQUIRE(parts.integral == 1);
  34. REQUIRE(parts.decimal == 175494);
  35. REQUIRE(parts.decimalPlaces == 6);
  36. REQUIRE(parts.exponent == -38);
  37. }
  38. }