box: fix update operations on the fixed-size floating-point fields#10779
Merged
locker merged 1 commit intotarantool:masterfrom Nov 5, 2024
Conversation
Contributor
Author
|
Alternative fix: diff --git a/src/box/field_def.c b/src/box/field_def.c
index 24b213154d..7826fb356b 100644
--- a/src/box/field_def.c
+++ b/src/box/field_def.c
@@ -91,8 +91,8 @@ const uint32_t field_mp_type[] = {
/* [FIELD_TYPE_UINT32] = */ 1U << MP_UINT,
/* [FIELD_TYPE_INT64] = */ (1U << MP_UINT) | (1U << MP_INT),
/* [FIELD_TYPE_UINT64] = */ 1U << MP_UINT,
- /* [FIELD_TYPE_FLOAT32] = */ 1U << MP_FLOAT,
- /* [FIELD_TYPE_FLOAT64] = */ 1U << MP_DOUBLE,
+ /* [FIELD_TYPE_FLOAT32] = */ (1U << MP_FLOAT) | (1U << MP_DOUBLE),
+ /* [FIELD_TYPE_FLOAT64] = */ (1U << MP_FLOAT) | (1U << MP_DOUBLE),
};
static_assert(lengthof(field_mp_type) == field_type_MAX,
diff --git a/test/engine-luatest/gh_9548_fixed_size_numeric_types_test.lua b/test/engine-luatest/gh_9548_fixed_size_numeric_types_test.lua
index 685b7f504f..899673944d 100644
--- a/test/engine-luatest/gh_9548_fixed_size_numeric_types_test.lua
+++ b/test/engine-luatest/gh_9548_fixed_size_numeric_types_test.lua
@@ -153,29 +153,6 @@ g1.test_fixed_size_signed_json = function(cg)
test_fixed_size_signed(cg, {has_indexed_json_path = true})
end
--- Test fixed-size floating point types. There is no value range check.
--- float32 can store only MP_FLOAT, and float64 can store only MP_DOUBLE.
-g1.test_fixed_size_float = function(cg)
- cg.server:exec(function()
- local ffi = require('ffi')
- local s = box.space.test
- s:format({{name = 'pk', type = 'unsigned'},
- {name = 'f32', type = 'float32' },
- {name = 'f64', type = 'float64' }})
- local float32 = ffi.cast('float', 12.34)
- local float64 = ffi.cast('double', 56.78)
- s:insert({0, float32, float64})
- t.assert_error_msg_equals(
- "Tuple field 2 (f32) type does not match one required by " ..
- "operation: expected float32, got double",
- s.insert, s, {1, float64, float64})
- t.assert_error_msg_equals(
- "Tuple field 3 (f64) type does not match one required by " ..
- "operation: expected float64, got float",
- s.insert, s, {1, float32, float32})
- end)
-end
-
-- Check that value range check works with nullable fields.
g1.test_nullable = function(cg)
cg.server:exec(function()
@@ -278,27 +255,6 @@ g1.test_format_change = function(cg)
allow = {'int64'},
forbid = {'int8', 'int16', 'int32'},
error = "exceeds the supported range for type"
- }, {
- type = 'double',
- value = ffi.cast('float', 123.456),
- allow = {'float32'},
- forbid = {'float64'},
- error = "type does not match one required by operation: " ..
- "expected float64, got float"
- }, {
- type = 'double',
- value = ffi.cast('double', 123.456),
- allow = {'float64'},
- forbid = {'float32'},
- error = "type does not match one required by operation: " ..
- "expected float32, got double"
- }, {
- type = 'float32',
- value = ffi.cast('float', 123.456),
- allow = {'double', 'any'},
- forbid = {'float64'},
- error = "type does not match one required by operation: " ..
- "expected float64, got float"
}
} |
14675d1 to
f1b11ee
Compare
Contributor
Author
|
Added testcase: s:replace({0, ffi.cast('float', -3.40e38),
ffi.cast('double', -3.40e38)})
s:replace({1, ffi.cast('float', 3.40e38),
ffi.cast('double', 3.40e38)})
s:update(0, {{'-', 'f32', ffi.cast('float', 3.40e38)},
{'-', 'f64', ffi.cast('double', 3.40e38)}})
s:update(1, {{'+', 'f32', ffi.cast('float', 3.40e38)},
{'+', 'f64', ffi.cast('double', 3.40e38)}})
t.assert_equals(s:select(), {{0, -math.huge, -6.8e38},
{1, math.huge, 6.8e38}}) |
locker
approved these changes
Nov 2, 2024
nshy
approved these changes
Nov 2, 2024
xuniq
approved these changes
Nov 5, 2024
changelogs/unreleased/gh-9929-fix-updates-on-fixed-size-fp-fields.md
Outdated
Show resolved
Hide resolved
Currently for floating-point arithmetic operations the smallest type that can represent the resulting value is chosen (MP_FLOAT vs. MP_DOUBLE). This doesn't work for fixed-size field types (float32 and float64) that require the data to be encoded only to the corresponding type. Closes tarantool#9929 Follow-up tarantool#9548 NO_DOC=bugfix
f1b11ee to
06ccd09
Compare
Member
|
Cherry-picked to 3.2. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently for floating-point arithmetic operations the smallest type that can represent the resulting value is chosen (
MP_FLOATvs.MP_DOUBLE).This doesn't work for fixed-size field types (
float32andfloat64) that require the data to be encoded only to the corresponding type.Closes #9929
Follow-up #9548