From 74eab303eab9a2e6b5c3346967d4dd6320abe610 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Wed, 25 Oct 2023 09:24:44 -0700 Subject: [PATCH] test some equation units and add some docs --- docs/user-guide/defined_units.rst | 4 ++ test/files/fuzz_issues/rtrip_fail37 | Bin 0 -> 9 bytes test/test_equation_units.cpp | 63 +++++++++++++++++++++------- units/r20_conv.cpp | 6 +-- units/unit_definitions.hpp | 18 ++++---- units/units.cpp | 6 +++ units/units_conversion_maps.hpp | 10 ++--- 7 files changed, 76 insertions(+), 31 deletions(-) create mode 100644 test/files/fuzz_issues/rtrip_fail37 diff --git a/docs/user-guide/defined_units.rst b/docs/user-guide/defined_units.rst index 2b2bc670..bf6d4f71 100644 --- a/docs/user-guide/defined_units.rst +++ b/docs/user-guide/defined_units.rst @@ -786,6 +786,9 @@ Some special units that were not otherwise characterized in namespace `units::pr - mach - mach number(multiplier of the speed of sound) - rootHertz - square root of Hertz, this is a special handling unit that triggers some specific behavior to handle it. - rootMeter - square root of meter, this is a special handling unit that triggers some specific behavior to handle it. +- degreeAPI - API scale for measuring liquid density typically petroleum based products +- degreeBaumeLight - scale for measuring liquid density for liquids lighter than water +- debreeBaumeHeavy - scale for measuring liquid density for liquids heavier than water Other Units @@ -807,6 +810,7 @@ Units related to climate in namespace `units::precise::climate` - gwp - global warming potential - gtp - global temperature potential +- odp - ozone depletion unit Speed Units ============================ diff --git a/test/files/fuzz_issues/rtrip_fail37 b/test/files/fuzz_issues/rtrip_fail37 new file mode 100644 index 0000000000000000000000000000000000000000..1f5f6604a4ccd6dcd1220994e4b850984fa22aab GIT binary patch literal 9 QcmZSB8 0.0) ? (140.0 / (130.0 + val)) : - (145.0 / (145.0 - val)); + case 17: // degrees Baume Light + return 140.0 / (130.0 + val); + case 18: // degrees Baume Heavy + return 145.0 / (145.0 - val); case 22: // saffir simpson hurricane wind scale { double out = -0.17613636364; @@ -1242,9 +1243,10 @@ namespace precise { return 0.5 * (std::log)(val); case 16: // API Gravity return 141.5 / (val)-131.5; - case 17: // degree Baume - return (val > 1.0) ? (145.0 * (1.0 - 1 / val)) : - (140.0 / val - 130); + case 17: // degree Baume Light + return 140.0 / val - 130; + case 18: // degree Baume Heavy + return 145.0 * (1.0 - 1.0 / val); case 22: // saffir simpson hurricane scale from wind speed { // using horners method on polynomial approximation of // saffir-simpson wind speed scale @@ -1412,8 +1414,10 @@ namespace precise { // for measuring density in liquids(mainly petroleum products) constexpr precise_unit degreeAPI = precise_unit(custom::equation_unit(16)) * g / mL; - constexpr precise_unit degreeBaume = + constexpr precise_unit degreeBaumeLight = precise_unit(custom::equation_unit(17)) * g / mL; + constexpr precise_unit degreeBaumeHeavy = + precise_unit(custom::equation_unit(18)) * g / mL; } // namespace special namespace other { diff --git a/units/units.cpp b/units/units.cpp index 456ca984..3fb724f1 100644 --- a/units/units.cpp +++ b/units/units.cpp @@ -2590,6 +2590,12 @@ static const std::unordered_map modifiers{ ckpair{"US dry", "US"}, ckpair{"USA", "US"}, ckpair{"USstatute", "US"}, + ckpair{"USheavy", "heavy"}, + ckpair{"USlight", "light"}, + ckpair{"Heavy", "heavy"}, + ckpair{"Light", "light"}, + ckpair{"heavy", "heavy"}, + ckpair{"light", "light"}, ckpair{"US statute", "US"}, ckpair{"statutory", "US"}, ckpair{"statute", "US"}, diff --git a/units/units_conversion_maps.hpp b/units/units_conversion_maps.hpp index 4e1c2033..19c0bff6 100644 --- a/units/units_conversion_maps.hpp +++ b/units/units_conversion_maps.hpp @@ -722,14 +722,14 @@ UNITS_CPP14_CONSTEXPR_OBJECT std::array< {"\xB0" "API", precise::special::degreeAPI}, // latin-1 degree - {"degBaume", precise::special::degreeBaume}, + {"degBaume", precise::special::degreeBaumeLight}, {u8"\u00B0Baume", - precise::special::degreeBaume}, // unicode degree symbol + precise::special::degreeBaumeLight}, // unicode degree symbol {"\xB0" "Baume", - precise::special::degreeBaume}, // latin-1 degree - {"degBaume(USheavy)", precise::special::degreeBaume}, - {"degBaume(USlight)", precise::special::degreeBaume}, + precise::special::degreeBaumeLight}, // latin-1 degree + {"degBaume_heavy", precise::special::degreeBaumeHeavy}, + {"degBaume_light", precise::special::degreeBaumeLight}, {"degBalling", {1.0, precise::generate_custom_unit(109), commodities::sugar}}, {"degBrix",