mirror of
https://github.com/zebrajr/pytorch.git
synced 2026-01-15 12:15:51 +00:00
Summary: There is a bug in integer div_mod that when the remainder is 0 and the divisor is negative, mod operation produces a negative number. Fixed in this PR. Pull Request resolved: https://github.com/pytorch/pytorch/pull/157383 Approved by: https://github.com/angelayi, https://github.com/jingsh
20 lines
550 B
C++
20 lines
550 B
C++
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
|
|
#include <c10/util/generic_math.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <cmath>
|
|
|
|
using namespace ::testing;
|
|
|
|
TEST(GenericMathTest, div_floor_test) {
|
|
EXPECT_EQ(c10::div_floor_floating(5., 0.), INFINITY);
|
|
EXPECT_DOUBLE_EQ(c10::div_floor_floating(5., 2.), 2.);
|
|
EXPECT_DOUBLE_EQ(c10::div_floor_floating(5., -2.), -3.);
|
|
EXPECT_EQ(c10::div_floor_integer(5, 2), 2);
|
|
EXPECT_EQ(c10::div_floor_integer(5, -2), -3);
|
|
EXPECT_EQ(c10::div_mod(-9, -3), 0);
|
|
EXPECT_EQ(c10::div_mod(-9., -3.), 0.);
|
|
}
|