Skip to content
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 f32/f64 comparison operators #449

Merged
merged 3 commits into from
Aug 10, 2020
Merged

Implement f32/f64 comparison operators #449

merged 3 commits into from
Aug 10, 2020

Conversation

axic
Copy link
Member

@axic axic commented Jul 31, 2020

Depends on #448.

Need to be cleaned up and unit tests.

@axic axic force-pushed the float-comparison branch 2 times, most recently from 0b749f0 to 6942142 Compare August 7, 2020 12:23
@axic axic changed the base branch from master to value-cast August 7, 2020 12:23
Base automatically changed from value-cast to master August 7, 2020 12:44
@axic axic force-pushed the float-comparison branch 3 times, most recently from 3d213ef to c2acfb3 Compare August 7, 2020 13:00
@chfast chfast force-pushed the float-comparison branch 2 times, most recently from 0cf4a4e to e4b50c2 Compare August 7, 2020 19:13
std::nextafter(-Limits::denorm_min(), -Limits::infinity()),
-Limits::denorm_min(),
TypeParam{0}, // FIXME.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the fixme here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was to add "negative zero" comparison.

}

// Negative zero.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these needed if we have -0 and 0 in ordered_values?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, its -1 and 0. Can we just have -0 there too?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values in the array must be strictly ordered, otherwise we don't know what result to expect. But -0 == 0.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why they need to be strictly ordered, to get the expected result you always calculate it as i op j anyway. Also as at some iterations i < j, at others j < i (and at some i == j)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please commit a change doing that because I don't see how this suppose to work.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, I misunderstood how it works first. But I pushed the way I thought it works first, it doesn't rely on strict ordering, what do you think?

@chfast chfast force-pushed the float-comparison branch from e4b50c2 to cc8dc5b Compare August 7, 2020 19:32
@codecov
Copy link

codecov bot commented Aug 7, 2020

Codecov Report

Merging #449 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           master     #449    +/-   ##
========================================
  Coverage   99.51%   99.52%            
========================================
  Files          54       54            
  Lines       15349    15507   +158     
========================================
+ Hits        15275    15433   +158     
  Misses         74       74            

@axic axic marked this pull request as ready for review August 7, 2020 19:40
@chfast chfast force-pushed the float-comparison branch 2 times, most recently from 4935d40 to d15f8b8 Compare August 10, 2020 09:09
EXPECT_THAT(execute(*inst, gt, {a, b}), Result(uint32_t{i > j})) << a << ">" << b;
EXPECT_THAT(execute(*inst, le, {a, b}), Result(uint32_t{i <= j})) << a << "<=" << b;
EXPECT_THAT(execute(*inst, ge, {a, b}), Result(uint32_t{i >= j})) << a << ">=" << b;
EXPECT_THAT(execute(*inst, eq, {a, b}), Result(uint32_t{a == b})) << a << "==" << b;
Copy link
Collaborator

@chfast chfast Aug 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to avoid using floating point comparison on the result side, because then the test is effectively EXPECT(a == b, a == b). This may be enough to detect a typo in the implementation, but if the C++ compiler is wrong, it is likely to be wrong in both places.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good point, I'd rather document these requirements/decision as comments in the test.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, feel free to delete my commit

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments and dropped the commit.

@chfast chfast merged commit 865d7e6 into master Aug 10, 2020
@chfast chfast deleted the float-comparison branch August 10, 2020 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants