Skip to content
Snippets Groups Projects
Commit f10255b1 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Use std::numeric_limits<T>::lowest()

Replace instances of -std::numeric_limits<T>::max()
by std::numeric_limits<T>::lowest() which is more generic
parent 1fc7e0b6
No related branches found
No related tags found
1 merge request!185Fix max of array types in the case of all non-positive values
......@@ -17,7 +17,7 @@ getBounds(const Mesh<2>& mesh, const RefNodeList& ref_node_list)
R2& xmax = bounds[1];
xmin = R2{std::numeric_limits<double>::max(), std::numeric_limits<double>::max()};
xmax = R2{-std::numeric_limits<double>::max(), -std::numeric_limits<double>::max()};
xmax = R2{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest()};
auto update_xmin = [](const R2& x, R2& x_min) {
if ((x[0] < x_min[0]) or ((x[0] == x_min[0]) and (x[1] < x_min[1]))) {
......@@ -118,12 +118,12 @@ getBounds(const Mesh<3>& mesh, const RefNodeList& ref_node_list)
ymin = R3{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), std::numeric_limits<double>::max()};
zmin = R3{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), std::numeric_limits<double>::max()};
xmax =
-R3{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), std::numeric_limits<double>::max()};
ymax =
-R3{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), std::numeric_limits<double>::max()};
zmax =
-R3{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), std::numeric_limits<double>::max()};
xmax = R3{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::lowest()};
ymax = R3{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::lowest()};
zmax = R3{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::lowest()};
const NodeValue<const R3>& xr = mesh.xr();
......
......@@ -61,7 +61,7 @@ class WriterBase : public IWriter
if (m_saved_times.size() > 0) {
return m_saved_times[m_saved_times.size() - 1];
} else {
return -std::numeric_limits<double>::max();
return std::numeric_limits<double>::lowest();
}
}
......@@ -77,7 +77,8 @@ class WriterBase : public IWriter
PeriodManager(const PeriodManager&) = default;
PeriodManager(PeriodManager&&) = default;
PeriodManager(double time_period) : m_time_period{time_period}, m_next_time{-std::numeric_limits<double>::max()} {}
PeriodManager(double time_period) : m_time_period{time_period}, m_next_time{std::numeric_limits<double>::lowest()}
{}
};
protected:
......
......@@ -25,12 +25,14 @@ class [[nodiscard]] SmallArray
friend SmallArray<std::add_const_t<DataType>>;
public:
PUGS_INLINE size_t size() const noexcept
PUGS_INLINE size_t
size() const noexcept
{
return m_size;
}
friend PUGS_INLINE SmallArray<std::remove_const_t<DataType>> copy(const SmallArray<DataType>& source)
friend PUGS_INLINE SmallArray<std::remove_const_t<DataType>>
copy(const SmallArray<DataType>& source)
{
SmallArray<std::remove_const_t<DataType>> image(source.m_size);
std::copy(source.m_values.get(), source.m_values.get() + source.m_size, image.m_values.get());
......@@ -38,28 +40,31 @@ class [[nodiscard]] SmallArray
return image;
}
friend PUGS_INLINE void copy_to(const SmallArray<DataType>& source,
const SmallArray<std::remove_const_t<DataType>>& destination)
friend PUGS_INLINE void
copy_to(const SmallArray<DataType>& source, const SmallArray<std::remove_const_t<DataType>>& destination)
{
Assert(source.size() == destination.size());
std::copy(source.m_values.get(), source.m_values.get() + source.m_size, destination.m_values.get());
}
PUGS_INLINE DataType& operator[](index_type i) const noexcept(NO_ASSERT)
PUGS_INLINE DataType&
operator[](index_type i) const noexcept(NO_ASSERT)
{
Assert(i < m_size);
return m_values[i];
}
PUGS_INLINE
void fill(const DataType& data) const
void
fill(const DataType& data) const
{
static_assert(not std::is_const_v<DataType>, "Cannot modify SmallArray of const");
std::fill(m_values.get(), m_values.get() + m_size, data);
}
template <typename DataType2>
PUGS_INLINE SmallArray& operator=(const SmallArray<DataType2>& array) noexcept
PUGS_INLINE SmallArray&
operator=(const SmallArray<DataType2>& array) noexcept
{
// ensures that DataType is the same as source DataType2
static_assert(std::is_same<std::remove_const_t<DataType>, std::remove_const_t<DataType2>>(),
......@@ -99,7 +104,8 @@ class [[nodiscard]] SmallArray
#endif // NDEBUG
}
friend std::ostream& operator<<(std::ostream& os, const SmallArray& x)
friend std::ostream&
operator<<(std::ostream& os, const SmallArray& x)
{
if (x.size() > 0) {
os << 0 << ':' << NaNHelper(x[0]);
......@@ -117,7 +123,8 @@ class [[nodiscard]] SmallArray
SmallArray(const SmallArray&) = default;
template <typename DataType2>
PUGS_INLINE SmallArray(const SmallArray<DataType2>& array) noexcept
PUGS_INLINE
SmallArray(const SmallArray<DataType2>& array) noexcept
{
this->operator=(array);
}
......@@ -172,7 +179,7 @@ max(const SmallArray<DataType>& array)
using data_type = std::remove_const_t<DataType>;
using index_type = typename SmallArray<DataType>::index_type;
data_type max_value = -std::numeric_limits<data_type>::max();
data_type max_value = std::numeric_limits<data_type>::lowest();
for (index_type i = 0; i < array.size(); ++i) {
if (array[i] > max_value) {
max_value = array[i];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment