-
Notifications
You must be signed in to change notification settings - Fork 998
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
fix(core): Auto cast doubles to ints in lua scripts #922
Conversation
24e0f84
to
725c9ba
Compare
src/core/interpreter.cc
Outdated
// Here is the use-case: | ||
// local foo = redis.call('zscore', 'myzset', 'one') | ||
// assert(type(foo) == "number") | ||
// We return doubles as strings likewise to Redis to maintain compatibility. |
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.
can we at least use a run-time flag for this?
src/server/multi_test.cc
Outdated
@@ -381,6 +381,10 @@ TEST_F(MultiTest, Eval) { | |||
ASSERT_THAT(resp, ArrLen(3)); | |||
const auto& arr = resp.GetVec(); | |||
EXPECT_THAT(arr, ElementsAre("a", "b", "c")); | |||
|
|||
Run({"zadd", "z1", "123", "a"}); | |||
resp = Run({"eval", "return redis.call('ZSCORE', KEYS[1], 'a') .. '-is-int'", "1", "z1"}); |
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.
I still need to understand. What did it return before?
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.
Specifically, maybe you can show the difference with tonumber
command? I did not understand from your comment above where DF fails
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.
123.0-is-int
725c9ba
to
25eb5aa
Compare
25eb5aa
to
7359de0
Compare
Signed-off-by: Vladislav Oleshko <[email protected]>
7359de0
to
7601c43
Compare
static constexpr double kConvertEps = std::numeric_limits<double>::epsilon(); | ||
|
||
double fractpart, intpart; | ||
fractpart = modf(d, &intpart); |
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.
I'm not sure epsilon is correct if the fractional part is taken from a large number. Does it hold up to max long?
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.
They scale in the example for comparing the difference, https://en.cppreference.com/w/cpp/types/numeric_limits/epsilon and in my mind modf cant improve on accuracy if a large number is already stored skewed
But I checked in the range of int64-max and values far from power of twos and it seems that modf(d) < double_eps is always the case 🔦
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.
lgtm
No description provided.