-
Notifications
You must be signed in to change notification settings - Fork 34
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
Implement int->float convert instructions #455
Conversation
037fe5c
to
72e9b4d
Compare
5dfd4ef
to
c1e1647
Compare
25c50ab
to
eca4e3f
Compare
EXPECT_THAT(execute(*instance, 0, {-max}), Result(-max_expected)); | ||
|
||
const auto min_expected = -std::pow(FloatT{2}, FloatT{IntLimits::digits}); |
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 wonder how std::pow
is implemented, is it guaranteed to always have the exact result for power of 2?
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 don't think pow()
matters here, but floating point types can represent all powers of 2 around integer ranges due to having the exponent part which produces 2^e
values.
a3c4df0
to
17bccc6
Compare
bd3ae4a
to
e5a3d18
Compare
Codecov Report
@@ Coverage Diff @@
## master #455 +/- ##
=======================================
Coverage 99.53% 99.53%
=======================================
Files 54 54
Lines 15926 16015 +89
=======================================
+ Hits 15852 15941 +89
Misses 74 74 |
template <typename SrcT, typename DstT> | ||
inline void convert(OperandStack& stack) noexcept | ||
{ | ||
stack.top() = static_cast<DstT>(stack.top().as<SrcT>()); |
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.
It's getting difficult to see which of these small helpers are suitable for which types. Maybe we should add static_assert
here that SrcT
is integer and DstT
is floating point?
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.
That's why I used FloatT
and IntT
in tests. I will try doing something about it here.
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.
These static asserts for types are nice, we should have them in each helper where it makes sense.
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.
Tests seems to be quite slim, but we can improve it later.
Here situation is simple - we convert an integer to the closer floating point value. No special cases as range of
f32
is greater thani64
.