Skip to content

Commit 3c6d004

Browse files
authored
[libc][math][c23] Fix implicit conversion in smoke tests for {fmax,fmin}f16 (#94624)
1 parent 5be0d00 commit 3c6d004

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

libc/test/src/math/smoke/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,7 @@ add_fp_unittest(
17051705
FMinTest.h
17061706
DEPENDS
17071707
libc.src.math.fminf
1708+
libc.src.__support.CPP.algorithm
17081709
libc.src.__support.FPUtil.fp_bits
17091710
)
17101711

@@ -1718,6 +1719,7 @@ add_fp_unittest(
17181719
FMinTest.h
17191720
DEPENDS
17201721
libc.src.math.fmin
1722+
libc.src.__support.CPP.algorithm
17211723
libc.src.__support.FPUtil.fp_bits
17221724
)
17231725

@@ -1731,6 +1733,7 @@ add_fp_unittest(
17311733
FMinTest.h
17321734
DEPENDS
17331735
libc.src.math.fminl
1736+
libc.src.__support.CPP.algorithm
17341737
libc.src.__support.FPUtil.fp_bits
17351738
)
17361739

@@ -1744,6 +1747,7 @@ add_fp_unittest(
17441747
FMinTest.h
17451748
DEPENDS
17461749
libc.src.math.fminf128
1750+
libc.src.__support.CPP.algorithm
17471751
libc.src.__support.FPUtil.fp_bits
17481752
)
17491753

@@ -1757,6 +1761,7 @@ add_fp_unittest(
17571761
FMinTest.h
17581762
DEPENDS
17591763
libc.src.math.fminf16
1764+
libc.src.__support.CPP.algorithm
17601765
libc.src.__support.FPUtil.fp_bits
17611766
)
17621767

@@ -1770,6 +1775,7 @@ add_fp_unittest(
17701775
FMaxTest.h
17711776
DEPENDS
17721777
libc.src.math.fmaxf
1778+
libc.src.__support.CPP.algorithm
17731779
libc.src.__support.FPUtil.fp_bits
17741780
)
17751781

@@ -1783,6 +1789,7 @@ add_fp_unittest(
17831789
FMaxTest.h
17841790
DEPENDS
17851791
libc.src.math.fmax
1792+
libc.src.__support.CPP.algorithm
17861793
libc.src.__support.FPUtil.fp_bits
17871794
)
17881795

@@ -1796,6 +1803,7 @@ add_fp_unittest(
17961803
FMaxTest.h
17971804
DEPENDS
17981805
libc.src.math.fmaxl
1806+
libc.src.__support.CPP.algorithm
17991807
libc.src.__support.FPUtil.fp_bits
18001808
)
18011809

@@ -1809,6 +1817,7 @@ add_fp_unittest(
18091817
FMaxTest.h
18101818
DEPENDS
18111819
libc.src.math.fmaxf128
1820+
libc.src.__support.CPP.algorithm
18121821
libc.src.__support.FPUtil.fp_bits
18131822
)
18141823

@@ -1822,6 +1831,7 @@ add_fp_unittest(
18221831
FMaxTest.h
18231832
DEPENDS
18241833
libc.src.math.fmaxf16
1834+
libc.src.__support.CPP.algorithm
18251835
libc.src.__support.FPUtil.fp_bits
18261836
)
18271837

libc/test/src/math/smoke/FMaxTest.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_LIBC_TEST_SRC_MATH_SMOKE_FMAXTEST_H
1010
#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_FMAXTEST_H
1111

12+
#include "src/__support/CPP/algorithm.h"
1213
#include "test/UnitTest/FEnvSafeTest.h"
1314
#include "test/UnitTest/FPMatcher.h"
1415
#include "test/UnitTest/Test.h"
@@ -55,10 +56,11 @@ class FMaxTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
5556
}
5657

5758
void testRange(FMaxFunc func) {
58-
constexpr StorageType COUNT = 100'001;
59-
constexpr StorageType STEP = STORAGE_MAX / COUNT;
60-
for (StorageType i = 0, v = 0, w = STORAGE_MAX; i <= COUNT;
61-
++i, v += STEP, w -= STEP) {
59+
constexpr int COUNT = 100'001;
60+
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
61+
static_cast<StorageType>(STORAGE_MAX / COUNT), StorageType(1));
62+
StorageType v = 0, w = STORAGE_MAX;
63+
for (int i = 0; i <= COUNT; ++i, v += STEP, w -= STEP) {
6264
FPBits xbits(v), ybits(w);
6365
if (xbits.is_inf_or_nan())
6466
continue;

libc/test/src/math/smoke/FMinTest.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_LIBC_TEST_SRC_MATH_SMOKE_FMINTEST_H
1010
#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_FMINTEST_H
1111

12+
#include "src/__support/CPP/algorithm.h"
1213
#include "test/UnitTest/FEnvSafeTest.h"
1314
#include "test/UnitTest/FPMatcher.h"
1415
#include "test/UnitTest/Test.h"
@@ -55,10 +56,11 @@ class FMinTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
5556
}
5657

5758
void testRange(FMinFunc func) {
58-
constexpr StorageType COUNT = 100'001;
59-
constexpr StorageType STEP = STORAGE_MAX / COUNT;
60-
for (StorageType i = 0, v = 0, w = STORAGE_MAX; i <= COUNT;
61-
++i, v += STEP, w -= STEP) {
59+
constexpr int COUNT = 100'001;
60+
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
61+
static_cast<StorageType>(STORAGE_MAX / COUNT), StorageType(1));
62+
StorageType v = 0, w = STORAGE_MAX;
63+
for (int i = 0; i <= COUNT; ++i, v += STEP, w -= STEP) {
6264
FPBits xbits(v), ybits(w);
6365
if (xbits.is_inf_or_nan())
6466
continue;

0 commit comments

Comments
 (0)