mirror of
https://github.com/vale981/ray
synced 2025-03-06 10:31:39 -05:00
[Core] Bug fix about FixedPoint (#22584)
* Fix FixedPoint::operator-(double const d) * add unit test * remove FixedPoint(uint32_t i) Co-authored-by: 黑驰 <senlin.zsl@antgroup.com>
This commit is contained in:
parent
3c707f70cc
commit
5efeb6534b
2 changed files with 26 additions and 6 deletions
|
@ -247,6 +247,30 @@ TEST_F(ClusterResourceSchedulerTest, SchedulingFixedPointTest) {
|
|||
|
||||
ASSERT_TRUE(fp1.Double() == 1.);
|
||||
}
|
||||
|
||||
{
|
||||
FixedPoint fp1(1.);
|
||||
auto fp2 = fp1 - 1.0;
|
||||
ASSERT_TRUE(fp2 == 0);
|
||||
|
||||
auto fp3 = fp1 + 1.0;
|
||||
ASSERT_TRUE(fp3 == 2);
|
||||
|
||||
auto fp4 = -fp1;
|
||||
ASSERT_TRUE(fp4 == -1.0);
|
||||
|
||||
fp1 = 2.0;
|
||||
ASSERT_TRUE(fp1 == 2.0);
|
||||
|
||||
FixedPoint fp5(-1.0);
|
||||
ASSERT_TRUE(fp5 == -1);
|
||||
|
||||
FixedPoint f6(-1);
|
||||
FixedPoint f7(int64_t(-1));
|
||||
ASSERT_TRUE(f6 == f7);
|
||||
|
||||
ASSERT_TRUE(f6 == -1.0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ClusterResourceSchedulerTest, SchedulingIdTest) {
|
||||
|
|
|
@ -27,16 +27,12 @@ class FixedPoint {
|
|||
|
||||
public:
|
||||
FixedPoint() : FixedPoint(0.0) {}
|
||||
FixedPoint(double d) { i_ = (uint64_t)(d * RESOURCE_UNIT_SCALING); } // NOLINT
|
||||
FixedPoint(double d) { i_ = (int64_t)(d * RESOURCE_UNIT_SCALING); } // NOLINT
|
||||
|
||||
FixedPoint(int i) { i_ = (i * RESOURCE_UNIT_SCALING); } // NOLINT
|
||||
|
||||
FixedPoint(uint32_t i) { i_ = (i * RESOURCE_UNIT_SCALING); } // NOLINT
|
||||
|
||||
FixedPoint(int64_t i) : FixedPoint((double)i) {} // NOLINT
|
||||
|
||||
FixedPoint(uint64_t i) : FixedPoint((double)i) {} // NOLINT
|
||||
|
||||
static FixedPoint Sum(const std::vector<FixedPoint> &list) {
|
||||
FixedPoint sum;
|
||||
for (auto &value : list) {
|
||||
|
@ -81,7 +77,7 @@ class FixedPoint {
|
|||
|
||||
FixedPoint operator-(double const d) const {
|
||||
FixedPoint res;
|
||||
res.i_ = i_ + static_cast<int64_t>(d * RESOURCE_UNIT_SCALING);
|
||||
res.i_ = i_ - static_cast<int64_t>(d * RESOURCE_UNIT_SCALING);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue