Repository navigation
Introduce a new NUMBER_VARINT_TUPLE encoding
#943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| vendorpull https://github.com/sourcemeta/vendorpull 1dcbac42809cf87cb5b045106b863e17ad84ba02 | ||
| core https://github.com/sourcemeta/core 614dd74eb014f50b4b83d81db3a39de43ffe83d0 | ||
| blaze https://github.com/sourcemeta/blaze 87b62693c610f7a07efb63d1a8baf22e99571aa9 | ||
| core https://github.com/sourcemeta/core af2b932ef6284c880f47012749b78bb75526f7a4 | ||
| blaze https://github.com/sourcemeta/blaze a5a019aa49139e7cd21accd52ad2c65f66afff16 | ||
| bootstrap https://github.com/twbs/bootstrap 1a6fdfae6be09b09eaced8f0e442ca6f7680a61e | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| #include <sourcemeta/jsonbinpack/runtime_decoder.h> | ||
|
|
||
| #include <sourcemeta/core/numeric.h> | ||
|
|
||
| #include <cmath> // std::isfinite | ||
| #include <cstdint> // std::int64_t, std::uint64_t | ||
|
|
||
| #if defined(__GNUC__) && !defined(__clang__) | ||
|
|
@@ -23,4 +26,38 @@ auto Decoder::DOUBLE_VARINT_TUPLE( | |
| return sourcemeta::core::JSON{static_cast<double>(digits) / divisor}; | ||
| } | ||
|
|
||
| auto Decoder::NUMBER_VARINT_TUPLE( | ||
| [[maybe_unused]] const struct NUMBER_VARINT_TUPLE &options) | ||
| -> sourcemeta::core::JSON { | ||
| #ifdef __clang__ | ||
| #pragma clang fp reciprocal(off) | ||
| #endif | ||
| const std::int64_t coefficient{this->get_varint_zigzag()}; | ||
| const std::uint64_t tag{this->get_varint()}; | ||
| const std::int64_t exponent{ | ||
| sourcemeta::core::zigzag_decode<std::uint64_t>(tag >> 1)}; | ||
|
|
||
| if ((tag & 1) != 0) { | ||
| return sourcemeta::core::JSON{ | ||
| sourcemeta::core::Decimal{coefficient}.scale_by( | ||
| sourcemeta::core::Decimal{exponent})}; | ||
| } | ||
|
|
||
| // A scale that has grown past the range of the type can only keep growing, | ||
| // so the loop stops there rather than counting out an exponent that a | ||
| // corrupt stream may have made arbitrarily large | ||
| const std::uint64_t shifts{exponent < 0 | ||
| ? static_cast<std::uint64_t>(-exponent) | ||
| : static_cast<std::uint64_t>(exponent)}; | ||
| double scale{1.0}; | ||
| for (std::uint64_t index = 0; index < shifts && std::isfinite(scale); | ||
| ++index) { | ||
| scale *= 10.0; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This decodes valid finite values with negative exponents beyond 308 as zero: Prompt for AI agents |
||
| } | ||
|
|
||
| return sourcemeta::core::JSON{exponent < 0 | ||
| ? static_cast<double>(coefficient) / scale | ||
| : static_cast<double>(coefficient) * scale}; | ||
| } | ||
|
|
||
| } // namespace sourcemeta::jsonbinpack | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,6 +114,10 @@ auto Encoder::ANY_PACKED_TYPE_TAG_BYTE_PREFIX( | |
| static_cast<std::uint8_t>(subtype << TYPE_SIZE)); | ||
| this->put_varint(absolute); | ||
| } | ||
| } else if (document.is_decimal()) { | ||
| this->put_byte(TYPE_OTHER | | ||
| static_cast<std::uint8_t>(SUBTYPE_DECIMAL << TYPE_SIZE)); | ||
| this->NUMBER_VARINT_TUPLE(document, {}); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: This sends every arbitrary-precision decimal through a tuple encoder limited to 19 significant digits: larger valid values abort in assertion-enabled builds and can encode incorrectly otherwise. Extend the coefficient encoding to preserve wider decimals before routing all decimal values here. Prompt for AI agents |
||
| } else if (document.is_string()) { | ||
| const sourcemeta::core::JSON::String &value{document.to_string()}; | ||
| const auto size{document.byte_size()}; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,8 +2,79 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <sourcemeta/core/numeric.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <cassert> // assert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <cstdint> // std::uint64_t | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <cassert> // assert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <charconv> // std::from_chars | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <cstddef> // std::size_t | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <cstdint> // std::int64_t, std::uint64_t | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <limits> // std::numeric_limits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <string_view> // std::string_view | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <system_error> // std::errc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifndef NDEBUG | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The widest coefficient that still fits in a signed 64-bit integer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constexpr std::size_t MAXIMUM_COEFFICIENT_DIGITS{19}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The coefficient and the base-10 exponent of an arbitrary precision decimal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Core keeps both of them private and only spells them out through the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // scientific form, as `[-]D[.DDDD]e(+|-)ADJUSTED`, whose exponent is adjusted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // to count from the leading digit rather than from the last one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto decimal_coefficient(const sourcemeta::core::Decimal &value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::int64_t &exponent) -> std::int64_t { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const auto scientific{value.reduce().to_scientific_string()}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const std::string_view view{scientific}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const auto marker{view.find('e')}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert(marker != std::string_view::npos); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto mantissa{view.substr(0, marker)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const auto negative{mantissa.front() == '-'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (negative) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mantissa.remove_prefix(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Every digit past the leading one sits after a decimal mark that the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // adjusted exponent already accounts for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const auto point{mantissa.find('.')}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const auto leading{mantissa.substr( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 0, point == std::string_view::npos ? mantissa.size() : point)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const auto trailing{point == std::string_view::npos | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? std::string_view{} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : mantissa.substr(point + 1)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const auto digits{leading.size() + trailing.size()}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert(digits >= 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert(digits <= MAXIMUM_COEFFICIENT_DIGITS); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::uint64_t magnitude{0}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const auto digit : leading) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| magnitude = (magnitude * 10) + static_cast<std::uint64_t>(digit - '0'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const auto digit : trailing) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| magnitude = (magnitude * 10) + static_cast<std::uint64_t>(digit - '0'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert(magnitude <= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static_cast<std::uint64_t>(std::numeric_limits<std::int64_t>::max())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto adjusted_exponent{view.substr(marker + 1)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (adjusted_exponent.front() == '+') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| adjusted_exponent.remove_prefix(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::int64_t adjusted{0}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [[maybe_unused]] const auto conversion{std::from_chars( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| adjusted_exponent.data(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| adjusted_exponent.data() + adjusted_exponent.size(), adjusted)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert(conversion.ec == std::errc{}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exponent = adjusted - static_cast<std::int64_t>(digits - 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const auto coefficient{static_cast<std::int64_t>(magnitude)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return negative ? -coefficient : coefficient; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+58
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } // namespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace sourcemeta::jsonbinpack { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -19,4 +90,26 @@ auto Encoder::DOUBLE_VARINT_TUPLE( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this->put_varint(point_position); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto Encoder::NUMBER_VARINT_TUPLE( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const sourcemeta::core::JSON &document, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [[maybe_unused]] const struct NUMBER_VARINT_TUPLE &options) -> void { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert(document.is_real() || document.is_decimal()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: This rejects valid integer instances such as Prompt for AI agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const auto decimal{document.is_decimal()}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::int64_t coefficient{0}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::int64_t exponent{0}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (decimal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| coefficient = decimal_coefficient(document.to_decimal(), exponent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::uint64_t point_position; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| coefficient = sourcemeta::core::real_digits<std::int64_t>( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Prompt for AI agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| document.to_real(), point_position); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exponent = -static_cast<std::int64_t>(point_position); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this->put_varint_zigzag(coefficient); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this->put_varint((sourcemeta::core::zigzag_encode(exponent) << 1) | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static_cast<std::uint64_t>(decimal)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } // namespace sourcemeta::jsonbinpack | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,7 @@ struct FLOOR_MULTIPLE_ENUM_VARINT; | |||||||||
| struct ROOF_MULTIPLE_MIRROR_ENUM_VARINT; | ||||||||||
| struct ARBITRARY_MULTIPLE_ZIGZAG_VARINT; | ||||||||||
| struct DOUBLE_VARINT_TUPLE; | ||||||||||
| struct NUMBER_VARINT_TUPLE; | ||||||||||
| struct BYTE_CHOICE_INDEX; | ||||||||||
| struct LARGE_CHOICE_INDEX; | ||||||||||
| struct TOP_LEVEL_BYTE_CHOICE_INDEX; | ||||||||||
|
|
@@ -55,7 +56,8 @@ using Encoding = std::variant< | |||||||||
| BOUNDED_8BIT_PREFIX_UTF8_STRING_SHARED, RFC3339_DATE_INTEGER_TRIPLET, | ||||||||||
| PREFIX_VARINT_LENGTH_STRING_SHARED, FIXED_TYPED_ARRAY, | ||||||||||
| BOUNDED_8BITS_TYPED_ARRAY, FLOOR_TYPED_ARRAY, ROOF_TYPED_ARRAY, | ||||||||||
| FIXED_TYPED_ARBITRARY_OBJECT, VARINT_TYPED_ARBITRARY_OBJECT>; | ||||||||||
| FIXED_TYPED_ARBITRARY_OBJECT, VARINT_TYPED_ARBITRARY_OBJECT, | ||||||||||
| NUMBER_VARINT_TUPLE>; | ||||||||||
|
|
||||||||||
| // The encoding names are the ones the JSON BinPack specification | ||||||||||
| // defines, so they keep their casing rather than following the C++ | ||||||||||
|
|
@@ -265,6 +267,57 @@ struct ARBITRARY_MULTIPLE_ZIGZAG_VARINT { | |||||||||
| // clang-format on | ||||||||||
| struct DOUBLE_VARINT_TUPLE {}; | ||||||||||
|
|
||||||||||
| // clang-format off | ||||||||||
| /// @brief The encoding consists of a sequence of two integers. The first is | ||||||||||
| /// the signed coefficient of the number as a ZigZag-encoded Base-128 64-bit | ||||||||||
| /// Little Endian variable-length unsigned integer. The second is the base-10 | ||||||||||
| /// exponent that the coefficient is scaled by, ZigZag-encoded and shifted left | ||||||||||
| /// by one bit, whose least significant bit is set when the number is an | ||||||||||
| /// arbitrary-precision decimal rather than a double, as a Base-128 64-bit | ||||||||||
| /// Little Endian variable-length unsigned integer. | ||||||||||
| /// | ||||||||||
| /// Unlike DOUBLE_VARINT_TUPLE, this encoding covers both of the numeric | ||||||||||
| /// representations that a JSON document may hold, and the schema-driven mode | ||||||||||
| /// relies on that: a schema that permits a number cannot tell which of the two | ||||||||||
| /// an instance will carry, so the distinction travels with the data. The | ||||||||||
| /// exponent is signed so that magnitudes a decimal mark cannot reach, such as | ||||||||||
| /// 1e300, remain within the encoding. | ||||||||||
| /// | ||||||||||
| /// ### Options | ||||||||||
| /// | ||||||||||
| /// None | ||||||||||
| /// | ||||||||||
| /// ### Conditions | ||||||||||
| /// | ||||||||||
| /// The coefficient must fit in a signed 64-bit integer, which holds every | ||||||||||
| /// number of up to 19 significant digits | ||||||||||
| /// | ||||||||||
|
Comment on lines
+293
to
+294
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: Prompt for AI agents
Suggested change
|
||||||||||
| /// ### Examples | ||||||||||
| /// | ||||||||||
| /// Given the decimal input value 2.1, the encoding results in the | ||||||||||
| /// variable-length integer 42 (the ZigZag encoding of 21) followed by the | ||||||||||
| /// variable-length unsigned integer 3 (the ZigZag encoding of the exponent -1, | ||||||||||
| /// shifted left by one bit, with the decimal bit set). | ||||||||||
| /// | ||||||||||
| /// ``` | ||||||||||
| /// +------+------+ | ||||||||||
| /// | 0x2a | 0x03 | | ||||||||||
| /// +------+------+ | ||||||||||
| /// ``` | ||||||||||
| /// | ||||||||||
| /// Given the double input value 3.14, the encoding results in the | ||||||||||
| /// variable-length integer 628 (the ZigZag encoding of 314) followed by the | ||||||||||
| /// variable-length unsigned integer 6 (the ZigZag encoding of the exponent -2, | ||||||||||
| /// shifted left by one bit, with the decimal bit clear). | ||||||||||
| /// | ||||||||||
| /// ``` | ||||||||||
| /// +------+------+------+ | ||||||||||
| /// | 0xf4 | 0x04 | 0x06 | | ||||||||||
| /// +------+------+------+ | ||||||||||
| /// ``` | ||||||||||
| // clang-format on | ||||||||||
| struct NUMBER_VARINT_TUPLE {}; | ||||||||||
|
|
||||||||||
| /// @} | ||||||||||
|
|
||||||||||
| /// @ingroup runtime | ||||||||||
|
|
@@ -445,6 +498,7 @@ constexpr std::uint8_t SUBTYPE_LONG_STRING_BASE_EXPONENT_7 = 0b00000111; | |||||||||
| constexpr std::uint8_t SUBTYPE_LONG_STRING_BASE_EXPONENT_8 = 0b00001000; | ||||||||||
| constexpr std::uint8_t SUBTYPE_LONG_STRING_BASE_EXPONENT_9 = 0b00001001; | ||||||||||
| constexpr std::uint8_t SUBTYPE_LONG_STRING_BASE_EXPONENT_10 = 0b00001010; | ||||||||||
| constexpr std::uint8_t SUBTYPE_DECIMAL = 0b00001011; | ||||||||||
|
|
||||||||||
| static_assert(SUBTYPE_FALSE <= sourcemeta::core::uint_max<SUBTYPE_SIZE>); | ||||||||||
| static_assert(SUBTYPE_TRUE <= sourcemeta::core::uint_max<SUBTYPE_SIZE>); | ||||||||||
|
|
@@ -464,6 +518,7 @@ static_assert(SUBTYPE_LONG_STRING_BASE_EXPONENT_9 <= | |||||||||
| sourcemeta::core::uint_max<SUBTYPE_SIZE>); | ||||||||||
| static_assert(SUBTYPE_LONG_STRING_BASE_EXPONENT_10 <= | ||||||||||
| sourcemeta::core::uint_max<SUBTYPE_SIZE>); | ||||||||||
| static_assert(SUBTYPE_DECIMAL <= sourcemeta::core::uint_max<SUBTYPE_SIZE>); | ||||||||||
|
|
||||||||||
| // Note that the binary values actually match the declared exponents | ||||||||||
| static_assert(SUBTYPE_LONG_STRING_BASE_EXPONENT_7 == 7); | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| version/* | ||
| version_* | ||
| workflowstestjobsm1matrixparametersa$% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: This Core pin makes Linux builds require OpenSSL 3.0 for Core crypto, although JSON BinPack does not link that library. Disable
SOURCEMETA_CORE_CRYPTOinFindCore.cmaketo keep builds working without OpenSSL.Prompt for AI agents