Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Fix several truncations and warnings in numerics #253

Merged
merged 5 commits into from
Mar 9, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#include <cuda/std/cfloat>
#include <cuda/std/cassert>

// MSVC has issues with producing INF with divisions by zero.
#if defined(_MSC_VER)
# include <cmath>
#endif

#include "test_macros.h"

template <class T>
Expand Down Expand Up @@ -53,10 +58,19 @@ int main(int, char**)
test<__int128_t>(0);
test<__uint128_t>(0);
#endif
#if !defined(_MSC_VER)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are these disabled on MSVC?

Copy link
Member Author

@wmaxey wmaxey Mar 8, 2022

Choose a reason for hiding this comment

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

Complaints of division by zero. I was going to @ you and ask about this one. Should we include host <cmath> and use some macro for INFINITY?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we silence the warning with a pragma?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is an outright error:

C:\Users\wmaxey\Documents\temp\libcudacxx\.upstream-tests\test\std\language.support\support.limits\limits\numeric.limits.members\infinity.pass.cpp(56): error #39-D: division by zero

C:\Users\wmaxey\Documents\temp\libcudacxx\.upstream-tests\test\std\language.support\support.limits\limits\numeric.limits.members\infinity.pass.cpp(57): error #39-D: division by zero

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm. Okay.

Yeah let's use INFINITY. I'd rather not have this commented out on MSVC.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in latest commit and tested on MSVC 14.30/16/12.

test<float>(1.f/0.f);
test<double>(1./0.);
#ifndef _LIBCUDACXX_HAS_NO_LONG_DOUBLE
# ifndef _LIBCUDACXX_HAS_NO_LONG_DOUBLE
test<long double>(1. / 0.);
# endif
// MSVC has issues with producing INF with divisions by zero.
#else
test<float>(INFINITY);
test<double>(INFINITY);
# ifndef _LIBCUDACXX_HAS_NO_LONG_DOUBLE
test<long double>(INFINITY);
# endif
#endif

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@

#include "test_macros.h"

#if defined(_MSC_VER)
// MSVC 14.12 erroneously notices an integer overflow
# pragma warning( disable: 4307 )
#endif

class A{};
enum E1 : unsigned char { rEd };
enum class E2 : unsigned char { red };
Expand Down
2 changes: 1 addition & 1 deletion .upstream-tests/test/std/numerics/complex.number/cases.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using testcases_t = cuda::std::complex<double>[152];
struct _testcases {
testcases_t _cases;

static constexpr size_t count = sizeof(_cases) / sizeof(_cases[0]);
static constexpr size_t count = sizeof(testcases_t) / sizeof(cuda::std::complex<double>);

__host__ __device__ const cuda::std::complex<double>* begin() const {
return &_cases[0];
Expand Down
2 changes: 1 addition & 1 deletion include/cuda/std/detail/libcxx/include/limits
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ protected:
template <class _Tp, int __digits, bool _IsSigned>
struct __libcpp_compute_min
{
static _LIBCUDACXX_CONSTEXPR const _Tp value = _Tp(_Tp(1) << __digits);
static _LIBCUDACXX_CONSTEXPR const _Tp value = static_cast<_Tp>(_Tp(1) << __digits);
};

template <class _Tp, int __digits>
Expand Down