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

Fix: max(int,int) returning double #3024

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stan/math/prim/fun/max.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace math {
* @return maximum value of the two arguments
*/
template <typename T1, typename T2, require_all_arithmetic_t<T1, T2>* = nullptr>
return_type_t<T1, T2> max(T1 x, T2 y) {
auto max(T1 x, T2 y) {
return std::max(x, y);
}

Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/min.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace math {
* @return minimum value of the two arguments
*/
template <typename T1, typename T2, require_all_arithmetic_t<T1, T2>* = nullptr>
return_type_t<T1, T2> min(T1 x, T2 y) {
auto min(T1 x, T2 y) {
return std::min(x, y);
}

Expand Down
8 changes: 8 additions & 0 deletions test/unit/math/prim/fun/max_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ TEST(MathMatrixPrimMat, max) {
EXPECT_FLOAT_EQ(2.0, max(m));
}

TEST(MathMatrixPrimMat, max_scalars) {
int a = 1, b = 2, c = 3;
int max_ab = stan::math::max(a, b);
EXPECT_EQ(2, max_ab);
int max_abc = stan::math::max(stan::math::max(a, b), c);
EXPECT_EQ(3, max_abc);
}

TEST(MathMatrixPrimMat, max_exception) {
using Eigen::Dynamic;
using Eigen::Matrix;
Expand Down
8 changes: 8 additions & 0 deletions test/unit/math/prim/fun/min_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ TEST(MathMatrixPrimMat, min) {
EXPECT_FLOAT_EQ(-10.0, min(m));
}

TEST(MathMatrixPrimMat, min_scalars) {
int a = 3, b = 2, c = 1;
int max_ab = stan::math::min(a, b);
EXPECT_EQ(2, max_ab);
int max_abc = stan::math::min(stan::math::min(a, b), c);
EXPECT_EQ(1, max_abc);
}

TEST(MathMatrixPrimMat, min_exception) {
using Eigen::Dynamic;
using Eigen::Matrix;
Expand Down