aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Göthel <[email protected]>2024-05-24 02:39:22 +0200
committerSven Göthel <[email protected]>2024-05-24 02:39:22 +0200
commitddb3dd8bc931ee72592d257791024fad8a2ddcf1 (patch)
tree56d05bf55eb83e91f41085415418ec244e6eb3ad
parentda80e9bd8b394bb9b4254701335ddaa2c633c89d (diff)
C++20 clang-tidy fixes
-rw-r--r--include/jau/counting_allocator.hpp8
-rw-r--r--include/jau/cow_darray.hpp8
-rw-r--r--include/jau/cow_vector.hpp4
-rw-r--r--include/jau/cpp_lang_util.hpp2
-rw-r--r--include/jau/ct_utils.hpp50
-rw-r--r--include/jau/dfa_utf8_decode.hpp7
-rw-r--r--include/jau/float_math.hpp37
-rw-r--r--include/jau/int_math.hpp6
-rw-r--r--include/jau/int_types.hpp9
-rw-r--r--include/jau/math/geom/frustum.hpp23
-rw-r--r--include/jau/math/mat4f.hpp68
-rw-r--r--include/jau/math/quaternion.hpp134
-rw-r--r--include/jau/mp/big_int.hpp16
-rw-r--r--include/jau/os/dyn_linker.hpp4
-rw-r--r--include/jau/os/func_resolver.hpp2
-rw-r--r--include/jau/os/native_lib.hpp4
-rw-r--r--include/jau/string_util.hpp4
-rw-r--r--include/jau/token_fsm.hpp12
-rw-r--r--include/jau/type_traits_queries.hpp6
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--test/test_eui48.cpp2
21 files changed, 206 insertions, 202 deletions
diff --git a/include/jau/counting_allocator.hpp b/include/jau/counting_allocator.hpp
index 169cce6..5e53793 100644
--- a/include/jau/counting_allocator.hpp
+++ b/include/jau/counting_allocator.hpp
@@ -159,7 +159,7 @@ struct counting_allocator : public std::allocator<T>
#if __cplusplus > 201703L
[[nodiscard]] constexpr value_type* allocate(std::size_t n) { // C++20
flush_stats();
- memory_usage += n * sizeof(value_type);
+ memory_usage += n * sizeof(value_type); // NOLINT(bugprone-sizeof-expression): Intended pointer type if so chosen
alloc_count++;
alloc_balance++;
return std::allocator<value_type>::allocate(n);
@@ -167,7 +167,7 @@ struct counting_allocator : public std::allocator<T>
#else
value_type* allocate(std::size_t n) { // C++17
flush_stats();
- memory_usage += n * sizeof(value_type);
+ memory_usage += n * sizeof(value_type); // NOLINT(bugprone-sizeof-expression): Intended pointer type if so chosen
alloc_count++;
alloc_balance++;
return std::allocator<value_type>::allocate(n);
@@ -177,7 +177,7 @@ struct counting_allocator : public std::allocator<T>
#if __cplusplus > 201703L
constexpr void deallocate(value_type* p, std::size_t n ) {
flush_stats();
- memory_usage -= n * sizeof(value_type);
+ memory_usage -= n * sizeof(value_type); // NOLINT(bugprone-sizeof-expression): Intended pointer type if so chosen
dealloc_count++;
alloc_balance--;
std::allocator<value_type>::deallocate(p, n);
@@ -185,7 +185,7 @@ struct counting_allocator : public std::allocator<T>
#else
void deallocate(value_type* p, std::size_t n ) {
flush_stats();
- memory_usage -= n * sizeof(value_type);
+ memory_usage -= n * sizeof(value_type); // NOLINT(bugprone-sizeof-expression): Intended pointer type if so chosen
dealloc_count++;
alloc_balance--;
std::allocator<value_type>::deallocate(p, n);
diff --git a/include/jau/cow_darray.hpp b/include/jau/cow_darray.hpp
index ab31070..fb058ed 100644
--- a/include/jau/cow_darray.hpp
+++ b/include/jau/cow_darray.hpp
@@ -26,13 +26,11 @@
#define JAU_COW_DARRAY_HPP_
#include <cstring>
+#include <numbers>
#include <string>
-#include <cstdint>
#include <limits>
-#include <atomic>
#include <memory>
#include <mutex>
-#include <condition_variable>
#include <algorithm>
#include <jau/cpp_lang_util.hpp>
@@ -127,7 +125,7 @@ namespace jau {
{
public:
/** Default growth factor using the golden ratio 1.618 */
- constexpr static const float DEFAULT_GROWTH_FACTOR = 1.618f;
+ constexpr static const float DEFAULT_GROWTH_FACTOR = std::numbers::phi_v<float>; // 1.618f;
constexpr static const bool uses_memmove = use_memmove;
constexpr static const bool uses_secmem = use_secmem;
@@ -141,7 +139,7 @@ namespace jau {
typedef value_type& reference;
typedef const value_type& const_reference;
typedef Size_type size_type;
- typedef typename std::make_signed<size_type>::type difference_type;
+ typedef typename std::make_signed_t<size_type> difference_type;
typedef Alloc_type allocator_type;
typedef darray<value_type, size_type,
diff --git a/include/jau/cow_vector.hpp b/include/jau/cow_vector.hpp
index 8f1cf76..5765239 100644
--- a/include/jau/cow_vector.hpp
+++ b/include/jau/cow_vector.hpp
@@ -115,7 +115,7 @@ namespace jau {
typedef value_type& reference;
typedef const value_type& const_reference;
typedef std::size_t size_type;
- typedef typename std::make_signed<size_type>::type difference_type;
+ typedef typename std::make_signed_t<size_type> difference_type;
typedef Alloc_type allocator_type;
typedef std::vector<value_type, allocator_type> storage_t;
@@ -216,7 +216,7 @@ namespace jau {
* </p>
*/
constexpr_atomic
- cow_vector& operator=(cow_vector&& x) {
+ cow_vector& operator=(cow_vector&& x) noexcept {
// Strategy-2: Acquire locks of both, blocking
// - If somebody else holds the lock, we wait.
// - Then we own the lock for both instances
diff --git a/include/jau/cpp_lang_util.hpp b/include/jau/cpp_lang_util.hpp
index aa7b31c..691287a 100644
--- a/include/jau/cpp_lang_util.hpp
+++ b/include/jau/cpp_lang_util.hpp
@@ -780,7 +780,7 @@ namespace jau {
template <class Dest, class Source>
constexpr
typename std::enable_if_t<
- sizeof(Dest) == sizeof(Source) &&
+ sizeof(Dest) == sizeof(Source) && // NOLINT(bugprone-sizeof-expression): Intended, same pointer size
std::is_pointer_v<Source> &&
std::is_pointer_v<Dest>,
Dest>
diff --git a/include/jau/ct_utils.hpp b/include/jau/ct_utils.hpp
index e23eaf5..31962ce 100644
--- a/include/jau/ct_utils.hpp
+++ b/include/jau/ct_utils.hpp
@@ -354,39 +354,37 @@ class Mask
T m_mask;
};
-template<typename T>
-inline Mask<T> conditional_copy_mem(T cnd,
- T* to,
- const T* from0,
- const T* from1,
- size_t elems) noexcept
- {
- const auto mask = CT::Mask<T>::expand(cnd);
- mask.select_n(to, from0, from1, elems);
- return mask;
+ template <typename T>
+ inline Mask<T> conditional_copy_mem(T cnd,
+ T* to,
+ const T* from0,
+ const T* from1,
+ size_t elems) noexcept {
+ const auto mask = CT::Mask<T>::expand(cnd);
+ mask.select_n(to, from0, from1, elems);
+ return mask;
}
-template<typename T>
-inline void conditional_swap(bool cnd, T& x, T& y) noexcept
- {
- const auto swap = CT::Mask<T>::expand(cnd);
+ template <typename T>
+ inline void conditional_swap(bool cnd, T& x, T& y) noexcept {
+ const auto swap = CT::Mask<T>::expand(cnd);
- T t0 = swap.select(y, x);
- T t1 = swap.select(x, y);
- x = t0;
- y = t1;
+ T t0 = swap.select(y, x);
+ T t1 = swap.select(x, y);
+ x = t0;
+ y = t1;
}
-template<typename T>
-inline void conditional_swap_ptr(bool cnd, T& x, T& y) noexcept
- {
- uintptr_t xp = reinterpret_cast<uintptr_t>(x);
- uintptr_t yp = reinterpret_cast<uintptr_t>(y);
+ template <typename T,
+ std::enable_if_t<std::is_pointer_v<T>, bool> = true>
+ inline void conditional_swap_ptr(bool cnd, T& x, T& y) noexcept {
+ uintptr_t xp = reinterpret_cast<uintptr_t>(x);
+ uintptr_t yp = reinterpret_cast<uintptr_t>(y);
- conditional_swap<uintptr_t>(cnd, xp, yp);
+ conditional_swap<uintptr_t>(cnd, xp, yp);
- x = reinterpret_cast<T>(xp);
- y = reinterpret_cast<T>(yp);
+ x = reinterpret_cast<T>(xp); // NOLINT(performance-no-int-to-ptr): Intended
+ y = reinterpret_cast<T>(yp); // NOLINT(performance-no-int-to-ptr): Intended
}
} // jau::ct
diff --git a/include/jau/dfa_utf8_decode.hpp b/include/jau/dfa_utf8_decode.hpp
index efe6de5..9d87718 100644
--- a/include/jau/dfa_utf8_decode.hpp
+++ b/include/jau/dfa_utf8_decode.hpp
@@ -27,14 +27,13 @@
#ifndef JAU_DFA_UTF8_DECODE_HPP_
#define JAU_DFA_UTF8_DECODE_HPP_
-#define DFA_UTF8_ACCEPT 0
-#define DFA_UTF8_REJECT 12
-
#include <string>
#include <cstdint>
-#include <cinttypes>
namespace jau {
+ constexpr static const uint32_t DFA_UTF8_ACCEPT = 0;
+ constexpr static const uint32_t DFA_UTF8_REJECT = 12;
+
/**
* \ingroup ByteUtils
*
diff --git a/include/jau/float_math.hpp b/include/jau/float_math.hpp
index 8d8600e..b3420f4 100644
--- a/include/jau/float_math.hpp
+++ b/include/jau/float_math.hpp
@@ -28,7 +28,6 @@
#include <cmath>
#include <climits>
#include <type_traits>
-#include <algorithm>
#include <jau/base_math.hpp>
#include <jau/string_util.hpp>
@@ -50,8 +49,8 @@ namespace jau {
using namespace jau::int_literals;
- typedef typename jau::uint_bytes<sizeof(float)>::type float_uint_t;
- typedef typename jau::uint_bytes<sizeof(double)>::type double_uint_t;
+ typedef typename jau::uint_bytes_t<sizeof(float)> float_uint_t;
+ typedef typename jau::uint_bytes_t<sizeof(double)> double_uint_t;
/** Signed bit 31 of IEEE 754 (IEC 559) single float-point bit layout, i.e. `0x80000000`. */
constexpr uint32_t const float_iec559_sign_bit = 1_u32 << 31; // 0x80000000_u32;
@@ -125,10 +124,10 @@ namespace jau {
*/
template<class T,
std::enable_if_t<std::is_floating_point_v<T>, bool> = true>
- typename jau::uint_bytes<sizeof(T)>::type
+ typename jau::uint_bytes_t<sizeof(T)>
bit_value_raw(const T a) noexcept
{
- typedef typename jau::uint_bytes<sizeof(T)>::type T_uint;
+ typedef typename jau::uint_bytes_t<sizeof(T)> T_uint;
union { T_uint u; T f; } iec559 = { .f = a };
return iec559.u;
}
@@ -237,7 +236,7 @@ namespace jau {
* @return machine epsilon of T
*/
template<class T>
- typename std::enable_if<std::is_floating_point_v<T>, T>::type
+ typename std::enable_if_t<std::is_floating_point_v<T>, T>
machineEpsilon() noexcept
{
const T one(1);
@@ -251,28 +250,28 @@ namespace jau {
/** Returns true if the given value is less than epsilon, w/ epsilon > 0. */
template<class T>
- typename std::enable_if<std::is_floating_point_v<T>, bool>::type
+ typename std::enable_if_t<std::is_floating_point_v<T>, bool>
constexpr is_zero(const T& a, const T& epsilon=std::numeric_limits<T>::epsilon()) noexcept {
return std::abs(a) < epsilon;
}
/** Returns true if all given values a and b are less than epsilon, w/ epsilon > 0. */
template<class T>
- typename std::enable_if<std::is_floating_point_v<T>, bool>::type
+ typename std::enable_if_t<std::is_floating_point_v<T>, bool>
constexpr is_zero2f(const T& a, const T& b, const T& epsilon=std::numeric_limits<T>::epsilon()) noexcept {
return std::abs(a) < epsilon && std::abs(b) < epsilon;
}
/** Returns true if all given values a, b and c are less than epsilon, w/ epsilon > 0. */
template<class T>
- typename std::enable_if<std::is_floating_point_v<T>, bool>::type
+ typename std::enable_if_t<std::is_floating_point_v<T>, bool>
constexpr is_zero3f(const T& a, const T& b, const T& c, const T& epsilon=std::numeric_limits<T>::epsilon()) noexcept {
return std::abs(a) < epsilon && std::abs(b) < epsilon && std::abs(c) < epsilon;
}
/** Returns true if all given values a, b, c and d are less than epsilon, w/ epsilon > 0. */
template<class T>
- typename std::enable_if<std::is_floating_point_v<T>, bool>::type
+ typename std::enable_if_t<std::is_floating_point_v<T>, bool>
constexpr is_zero4f(const T& a, const T& b, const T& c, const T& d, const T& epsilon=std::numeric_limits<T>::epsilon()) noexcept {
return std::abs(a) < epsilon && std::abs(b) < epsilon && std::abs(c) < epsilon && std::abs(d) < epsilon;
}
@@ -282,7 +281,7 @@ namespace jau {
* disregarding `epsilon` but considering `NaN`, `-Inf` and `+Inf`.
*/
template<class T>
- typename std::enable_if<std::is_floating_point_v<T>, bool>::type
+ typename std::enable_if_t<std::is_floating_point_v<T>, bool>
constexpr is_zero_raw(const T& a) noexcept {
return ( bit_value(a) & ~float_iec559_sign_bit ) == 0;
}
@@ -312,7 +311,7 @@ namespace jau {
return 1; // Neither is NaN, a is larger
}
// a == b: we compare the _signed_ int value
- typedef typename jau::uint_bytes<sizeof(T)>::type T_uint;
+ typedef typename jau::uint_bytes_t<sizeof(T)> T_uint;
typedef typename std::make_signed_t<T_uint> T_int;
const T_int a_bits = static_cast<T_int>( bit_value(a) );
const T_int b_bits = static_cast<T_int>( bit_value(b) );
@@ -367,7 +366,7 @@ namespace jau {
* @param b value to compare
*/
template<class T>
- typename std::enable_if<std::is_floating_point_v<T>, bool>::type
+ typename std::enable_if_t<std::is_floating_point_v<T>, bool>
constexpr equals_raw(const T& a, const T& b) noexcept {
// Values are equal (Inf, Nan .. )
return bit_value(a) == bit_value(b);
@@ -390,7 +389,7 @@ namespace jau {
* @param epsilon defaults to std::numeric_limits<T>::epsilon(), must be > 0
*/
template<class T>
- typename std::enable_if<std::is_floating_point_v<T>, bool>::type
+ typename std::enable_if_t<std::is_floating_point_v<T>, bool>
constexpr equals(const T& a, const T& b, const T& epsilon=std::numeric_limits<T>::epsilon()) noexcept {
if( std::abs(a - b) < epsilon ) {
return true;
@@ -409,7 +408,7 @@ namespace jau {
* @param b value to compare
*/
template<class T>
- typename std::enable_if<std::is_floating_point_v<T>, bool>::type
+ typename std::enable_if_t<std::is_floating_point_v<T>, bool>
constexpr equals2(const T& a, const T& b, const T& epsilon=std::numeric_limits<T>::epsilon()) noexcept {
return std::abs(a - b) < epsilon;
}
@@ -432,7 +431,7 @@ namespace jau {
* @param epsilon the machine epsilon of type T, defaults to <code>std::numeric_limits<T>::epsilon()</code>
*/
template<class T>
- typename std::enable_if<std::is_floating_point_v<T>, bool>::type
+ typename std::enable_if_t<std::is_floating_point_v<T>, bool>
constexpr equals(const T& a, const T& b, int ulp, const T& epsilon=std::numeric_limits<T>::epsilon()) noexcept {
return equals(a, b, epsilon * ulp);
}
@@ -456,7 +455,7 @@ namespace jau {
* @param epsilon the machine epsilon of type T, defaults to <code>std::numeric_limits<T>::epsilon()</code>
*/
template<class T>
- typename std::enable_if<std::is_floating_point_v<T>, bool>::type
+ typename std::enable_if_t<std::is_floating_point_v<T>, bool>
almost_equal(const T& a, const T& b, int ulp=1, const T& epsilon=std::numeric_limits<T>::epsilon()) noexcept
{
const T diff = std::fabs(a-b);
@@ -472,8 +471,8 @@ namespace jau {
/** Returns the rounded value cast to int. */
template<class T,
std::enable_if_t<std::is_floating_point_v<T>, bool> = true>
- constexpr typename jau::sint_bytes<sizeof(T)>::type round_to_int(const T v) noexcept {
- return static_cast<typename jau::sint_bytes<sizeof(T)>::type>( std::round(v) );
+ constexpr typename jau::sint_bytes_t<sizeof(T)> round_to_int(const T v) noexcept {
+ return static_cast<typename jau::sint_bytes_t<sizeof(T)>>( std::round(v) );
}
/** Converts arc-degree to radians */
diff --git a/include/jau/int_math.hpp b/include/jau/int_math.hpp
index eefc94f..4e7aedc 100644
--- a/include/jau/int_math.hpp
+++ b/include/jau/int_math.hpp
@@ -54,7 +54,7 @@ namespace jau {
/** Returns true of the given integer value is zero. */
template<class T>
- typename std::enable_if<std::is_integral_v<T>, bool>::type
+ typename std::enable_if_t<std::is_integral_v<T>, bool>
constexpr is_zero(const T& a) noexcept {
return 0 == a;
}
@@ -67,7 +67,7 @@ namespace jau {
* @param b value to compare
*/
template<class T>
- typename std::enable_if<std::is_integral_v<T>, bool>::type
+ typename std::enable_if_t<std::is_integral_v<T>, bool>
constexpr equals(const T& a, const T& b) noexcept {
return a == b;
}
@@ -81,7 +81,7 @@ namespace jau {
* @param allowed_deviation allowed deviation
*/
template<class T>
- typename std::enable_if<std::is_integral_v<T>, bool>::type
+ typename std::enable_if_t<std::is_integral_v<T>, bool>
constexpr equals(const T& a, const T& b, const T& allowed_deviation) noexcept {
return std::abs(a - b) <= allowed_deviation;
}
diff --git a/include/jau/int_types.hpp b/include/jau/int_types.hpp
index d6968e9..1111334 100644
--- a/include/jau/int_types.hpp
+++ b/include/jau/int_types.hpp
@@ -73,6 +73,9 @@ namespace jau {
#if defined(__SIZEOF_INT128__)
template <> struct uint_bytes<16>{ using type = uint128_t; };
#endif
+ /// Alias template for uint_bytes
+ template <int bytesize>
+ using uint_bytes_t = typename uint_bytes<bytesize>::type;
template <int bytesize> struct sint_bytes;
template <> struct sint_bytes<4>{ using type = int32_t; };
@@ -80,11 +83,17 @@ namespace jau {
#if defined(__SIZEOF_INT128__)
template <> struct sint_bytes<16>{ using type = int128_t; };
#endif
+ /// Alias template for sint_bytes
+ template <int bytesize>
+ using sint_bytes_t = typename sint_bytes<bytesize>::type;
template <int bytesize> struct float_bytes;
template <> struct float_bytes<sizeof(float)>{ using type = float; };
template <> struct float_bytes<sizeof(double)>{ using type = double; };
template <> struct float_bytes<sizeof(long double)>{ using type = long double; };
+ /// Alias template for float_bytes
+ template <int bytesize>
+ using float_bytes_t = typename float_bytes<bytesize>::type;
/**
// *************************************************
diff --git a/include/jau/math/geom/frustum.hpp b/include/jau/math/geom/frustum.hpp
index e516efb..e8e084b 100644
--- a/include/jau/math/geom/frustum.hpp
+++ b/include/jau/math/geom/frustum.hpp
@@ -26,12 +26,9 @@
#include <cmath>
#include <cstdarg>
-#include <cstdint>
-#include <limits>
#include <string>
#include <jau/float_math.hpp>
-#include <jau/math/math_error.hpp>
#include <jau/math/vec3f.hpp>
#include <jau/math/vec4f.hpp>
#include <jau/math/mat4f.hpp>
@@ -288,12 +285,12 @@ class Frustum {
* @return {@code out} for chaining
*/
constexpr void getPlanes(float out[/* off+4*6] */]) const noexcept {
- planes[LEFT ].toFloats(out+4*0);
- planes[RIGHT ].toFloats(out+4*1);
- planes[BOTTOM].toFloats(out+4*2);
- planes[TOP ].toFloats(out+4*3);
- planes[NEAR ].toFloats(out+4*4);
- planes[FAR ].toFloats(out+4*5);
+ planes[LEFT ].toFloats( out + static_cast<ptrdiff_t>(4*0) );
+ planes[RIGHT ].toFloats( out + static_cast<ptrdiff_t>(4*1) );
+ planes[BOTTOM].toFloats( out + static_cast<ptrdiff_t>(4*2) );
+ planes[TOP ].toFloats( out + static_cast<ptrdiff_t>(4*3) );
+ planes[NEAR ].toFloats( out + static_cast<ptrdiff_t>(4*4) );
+ planes[FAR ].toFloats( out + static_cast<ptrdiff_t>(4*5) );
}
/**
@@ -352,7 +349,7 @@ class Frustum {
* @see Matrix4f#updateFrustumPlanes(Frustum)
* @see Matrix4f#getFrustum(Frustum, FovDesc)
*/
- Mat4f& updateByFovDesc(jau::math::Mat4f& m, const FovDesc& fovDesc) noexcept {
+ Mat4f& updateByFovDesc(jau::math::Mat4f& m, const FovDesc& fovDesc) {
m.setToPerspective(fovDesc.fovhv, fovDesc.zNear, fovDesc.zFar);
setFromMat(m);
return m;
@@ -428,7 +425,7 @@ class Frustum {
}
// Normalize all planes
- for (int i = 0; i < 6; ++i) {
+ for (int i = 0; i < 6; ++i) { // NOLINT(modernize-loop-convert)
geom::Frustum::Plane& p = planes[i];
const float invLen = 1.0f / p.n.length();
p.n *= invLen;
@@ -480,7 +477,7 @@ class Frustum {
location_t classifyPoint(const Vec3f& p) const noexcept {
location_t res = location_t::INSIDE;
- for (int i = 0; i < 6; ++i) {
+ for (int i = 0; i < 6; ++i) { // NOLINT(modernize-loop-convert)
const float d = planes[i].distanceTo(p);
if ( d < 0.0f ) {
return location_t::OUTSIDE;
@@ -516,7 +513,7 @@ class Frustum {
location_t classifySphere(const Vec3f& p, const float radius) const noexcept {
location_t res = location_t::INSIDE; // fully inside
- for (int i = 0; i < 6; ++i) {
+ for (int i = 0; i < 6; ++i) { // NOLINT(modernize-loop-convert)
const float d = planes[i].distanceTo(p);
if ( d < -radius ) {
// fully outside
diff --git a/include/jau/math/mat4f.hpp b/include/jau/math/mat4f.hpp
index f016f3a..beee5f5 100644
--- a/include/jau/math/mat4f.hpp
+++ b/include/jau/math/mat4f.hpp
@@ -40,6 +40,7 @@
#include <jau/math/vec4f.hpp>
#include <jau/math/recti.hpp>
#include <jau/math/fov_hv_halves.hpp>
+#include <jau/int_types.hpp>
namespace jau::math::geom {
class Frustum; // forward
@@ -357,10 +358,11 @@ class alignas(Value_type) Matrix4 {
* @return given result vector <i>v_out</i> for chaining
*/
constexpr Vec4& getRow(const jau::nsize_t row, Vec4& v_out) const noexcept {
- return v_out.set( get(row+0*4),
- get(row+1*4),
- get(row+2*4),
- get(row+3*4) );
+ using namespace jau::int_literals;
+ return v_out.set( get( row + 0*4_unz),
+ get( row + 1*4_unz),
+ get( row + 2*4_unz),
+ get( row + 3*4_unz) );
}
/**
* Get the named column of the given column-major matrix to v_out w/o boundary check.
@@ -368,10 +370,11 @@ class alignas(Value_type) Matrix4 {
* @return result vector holding the requested row
*/
constexpr Vec4 getRow(const jau::nsize_t row) const noexcept {
- return Vec4( get(row+0*4),
- get(row+1*4),
- get(row+2*4),
- get(row+3*4) );
+ using namespace jau::int_literals;
+ return Vec4( get(row+0*4_unz),
+ get(row+1*4_unz),
+ get(row+2*4_unz),
+ get(row+3*4_unz) );
}
/**
@@ -381,10 +384,11 @@ class alignas(Value_type) Matrix4 {
* @return given result vector <i>v_out</i> for chaining
*/
constexpr Vec3& getRow(const jau::nsize_t row, Vec3& v_out) const noexcept {
+ using namespace jau::int_literals;
assert( row <= 2 );
- return v_out.set( get(row+0*4),
- get(row+1*4),
- get(row+2*4) );
+ return v_out.set( get(row+0*4_unz),
+ get(row+1*4_unz),
+ get(row+2*4_unz) );
}
/**
@@ -1472,7 +1476,7 @@ class alignas(Value_type) Matrix4 {
// rawWinPos = P * vec4Tmp2
// rawWinPos = P * ( Mv * o )
// rawWinPos = P * Mv * o
- Vec4 vec4Tmp2 = mMv * Vec4(obj, 1.0f);
+ Vec4 vec4Tmp2 = mMv * Vec4(obj, one);
Vec4 rawWinPos = mP * vec4Tmp2;
@@ -1483,7 +1487,7 @@ class alignas(Value_type) Matrix4 {
const value_type s = ( one / rawWinPos.w ) * half;
// Map x, y and z to range 0-1 (w is ignored)
- rawWinPos.scale(s).add(half, half, half, 0.0f);
+ rawWinPos.scale(s).add(half, half, half, zero);
// Map x,y to viewport
winPos.set( rawWinPos.x * viewport.width() + viewport.x(),
@@ -1518,7 +1522,7 @@ class alignas(Value_type) Matrix4 {
const value_type s = ( one / rawWinPos.w ) * half;
// Map x, y and z to range 0-1 (w is ignored)
- rawWinPos.scale(s).add(half, half, half, 0.0f);
+ rawWinPos.scale(s).add(half, half, half, zero);
// Map x,y to viewport
winPos.set( rawWinPos.x * viewport.width() + viewport.x(),
@@ -1556,13 +1560,13 @@ class alignas(Value_type) Matrix4 {
return false;
}
- Vec4 winPos(winx, winy, winz, 1.0f);
+ Vec4 winPos(winx, winy, winz, one);
// Map x and y from window coordinates
- winPos.add(-viewport.x(), -viewport.y(), 0.0f, 0.0f).mul(1.0f/viewport.width(), 1.0f/viewport.height(), 1.0f, 1.0f);
+ winPos.add(-viewport.x(), -viewport.y(), zero, zero).mul(one/viewport.width(), one/viewport.height(), one, one);
// Map to range -1 to 1
- winPos.mul(2.0f, 2.0f, 2.0f, 1.0f).add(-1.0f, -1.0f, -1.0f, 0.0f);
+ winPos.mul(two, two, two, one).add(-one, -one, -one, zero);
// rawObjPos = Inv(P x Mv) * winPos
Vec4 rawObjPos = invPMv * winPos;
@@ -1571,7 +1575,7 @@ class alignas(Value_type) Matrix4 {
return false;
}
- rawObjPos.scale(1.0f / rawObjPos.w).getVec3(objPos);
+ rawObjPos.scale(one / rawObjPos.w).getVec3(objPos);
return true;
}
@@ -1594,13 +1598,13 @@ class alignas(Value_type) Matrix4 {
const Recti& viewport,
Vec3& objPos) noexcept
{
- Vec4 winPos(winx, winy, winz, 1.0f);
+ Vec4 winPos(winx, winy, winz, one);
// Map x and y from window coordinates
- winPos.add(-viewport.x(), -viewport.y(), 0.0f, 0.0f).mul(1.0f/viewport.width(), 1.0f/viewport.height(), 1.0f, 1.0f);
+ winPos.add(-viewport.x(), -viewport.y(), zero, zero).mul(one/viewport.width(), one/viewport.height(), one, one);
// Map to range -1 to 1
- winPos.mul(2.0f, 2.0f, 2.0f, 1.0f).add(-1.0f, -1.0f, -1.0f, 0.0f);
+ winPos.mul(two, two, two, one).add(-one, -one, -one, zero);
// rawObjPos = Inv(P x Mv) * winPos
Vec4 rawObjPos = invPMv * winPos;
@@ -1609,7 +1613,7 @@ class alignas(Value_type) Matrix4 {
return false;
}
- rawObjPos.scale(1.0f / rawObjPos.w).getVec3(objPos);
+ rawObjPos.scale(one / rawObjPos.w).getVec3(objPos);
return true;
}
@@ -1634,13 +1638,13 @@ class alignas(Value_type) Matrix4 {
const Recti& viewport,
Vec3& objPos1, Vec3& objPos2) noexcept
{
- Vec4 winPos(winx, winy, winz1, 1.0f);
+ Vec4 winPos(winx, winy, winz1, one);
// Map x and y from window coordinates
- winPos.add(-viewport.x(), -viewport.y(), 0.0f, 0.0f).mul(1.0f/viewport.width(), 1.0f/viewport.height(), 1.0f, 1.0f);
+ winPos.add(-viewport.x(), -viewport.y(), zero, zero).mul(one/viewport.width(), one/viewport.height(), one, one);
// Map to range -1 to 1
- winPos.mul(2.0f, 2.0f, 2.0f, 1.0f).add(-1.0f, -1.0f, -1.0f, 0.0f);
+ winPos.mul(two, two, two, one).add(-one, -one, -one, zero);
// rawObjPos = Inv(P x Mv) * winPos1
Vec4 rawObjPos = invPMv * winPos;
@@ -1648,13 +1652,13 @@ class alignas(Value_type) Matrix4 {
if ( zero == rawObjPos.w ) {
return false;
}
- rawObjPos.scale(1.0f / rawObjPos.w).getVec3(objPos1);
+ rawObjPos.scale(one / rawObjPos.w).getVec3(objPos1);
//
// winz2
//
// Map Z to range -1 to 1
- winPos.z = winz2 * 2.0f - 1.0f;
+ winPos.z = winz2 * two - one;
// rawObjPos = Inv(P x Mv) * winPos2
invPMv.mulVec4(winPos, rawObjPos);
@@ -1662,7 +1666,7 @@ class alignas(Value_type) Matrix4 {
if ( zero == rawObjPos.w ) {
return false;
}
- rawObjPos.scale(1.0f / rawObjPos.w).getVec3(objPos2);
+ rawObjPos.scale(one / rawObjPos.w).getVec3(objPos2);
return true;
}
@@ -1701,10 +1705,10 @@ class alignas(Value_type) Matrix4 {
Vec4 winPos(winx, winy, winz, clipw);
// Map x and y from window coordinates
- winPos.add(-viewport.x(), -viewport.y(), -near, 0.0f).mul(1.0f/viewport.width(), 1.0f/viewport.height(), 1.0f/(far-near), 1.0f);
+ winPos.add(-viewport.x(), -viewport.y(), -near, zero).mul(one/viewport.width(), one/viewport.height(), one/(far-near), one);
// Map to range -1 to 1
- winPos.mul(2.0f, 2.0f, 2.0f, 1.0f).add(-1.0f, -1.0f, -1.0f, 0.0f);
+ winPos.mul(two, two, two, one).add(-one, -one, -one, zero);
// objPos = Inv(P x Mv) * winPos
invPMv.mulVec4(winPos, objPos);
@@ -1741,10 +1745,10 @@ class alignas(Value_type) Matrix4 {
Vec4 winPos(winx, winy, winz, clipw);
// Map x and y from window coordinates
- winPos.add(-viewport.x(), -viewport.y(), -near, 0.0f).mul(1.0f/viewport.width(), 1.0f/viewport.height(), 1.0f/(far-near), 1.0f);
+ winPos.add(-viewport.x(), -viewport.y(), -near, zero).mul(one/viewport.width(), one/viewport.height(), one/(far-near), one);
// Map to range -1 to 1
- winPos.mul(2.0f, 2.0f, 2.0f, 1.0f).add(-1.0f, -1.0f, -1.0f, 0.0f);
+ winPos.mul(two, two, two, one).add(-one, -one, -one, zero);
// objPos = Inv(P x Mv) * winPos
invPMv.mulVec4(winPos, objPos);
diff --git a/include/jau/math/quaternion.hpp b/include/jau/math/quaternion.hpp
index 3252852..38b50dc 100644
--- a/include/jau/math/quaternion.hpp
+++ b/include/jau/math/quaternion.hpp
@@ -126,10 +126,10 @@ class alignas(Value_type) Quaternion {
constexpr_cxx26 value_type magnitude() const noexcept {
const value_type magnitudeSQ = magnitudeSquared();
if ( jau::is_zero(magnitudeSQ) ) {
- return 0.0f;
+ return zero;
}
- if ( jau::equals(1.0f, magnitudeSQ) ) {
- return 1.0f;
+ if ( jau::equals(one, magnitudeSQ) ) {
+ return one;
}
return std::sqrt(magnitudeSQ);
}
@@ -174,7 +174,7 @@ class alignas(Value_type) Quaternion {
* </p>
*/
constexpr bool isIdentity() const noexcept {
- return jau::equals(1.0f, m_w) && jau::is_zero3f(m_x, m_y, m_z);
+ return jau::equals(one, m_w) && jau::is_zero3f(m_x, m_y, m_z);
// return m_w == 1f && m_x == 0f && m_y == 0f && m_z == 0f;
}
@@ -183,7 +183,7 @@ class alignas(Value_type) Quaternion {
* @return this quaternion for chaining.
*/
constexpr Quaternion& setIdentity() noexcept {
- m_x = m_y = m_z = 0.0f; m_w = 1.0f;
+ m_x = m_y = m_z = zero; m_w = one;
return *this;
}
@@ -202,7 +202,7 @@ class alignas(Value_type) Quaternion {
if ( jau::is_zero(norm) ) {
setIdentity();
} else {
- const value_type invNorm = 1.0f/norm;
+ const value_type invNorm = one/norm;
m_w *= invNorm;
m_x *= invNorm;
m_y *= invNorm;
@@ -236,10 +236,10 @@ class alignas(Value_type) Quaternion {
*/
constexpr Quaternion& invert() noexcept {
const value_type magnitudeSQ = magnitudeSquared();
- if ( jau::equals(1.0f, magnitudeSQ) ) {
+ if ( jau::equals(one, magnitudeSQ) ) {
conjugate();
} else {
- const value_type invmsq = 1.0f/magnitudeSQ;
+ const value_type invmsq = one/magnitudeSQ;
m_w *= invmsq;
m_x = -m_x * invmsq;
m_y = -m_y * invmsq;
@@ -340,7 +340,7 @@ class alignas(Value_type) Quaternion {
// no change
return *this;
}
- const value_type halfAngle = 0.5f * angle;
+ const value_type halfAngle = half * angle;
const value_type sin = std::sin(halfAngle);
const value_type qw = std::cos(halfAngle);
const value_type qx = sin * axisX;
@@ -376,7 +376,7 @@ class alignas(Value_type) Quaternion {
* @return this quaternion for chaining.
*/
constexpr_cxx26 Quaternion& rotateByAngleX(const value_type angle) noexcept {
- const value_type halfAngle = 0.5f * angle;
+ const value_type halfAngle = half * angle;
return rotateByAngleX(std::sin(halfAngle), std::cos(halfAngle));
}
/** Rotate this quaternion around X axis with the given angle's sin + cos values */
@@ -394,7 +394,7 @@ class alignas(Value_type) Quaternion {
* @return this quaternion for chaining.
*/
constexpr_cxx26 Quaternion& rotateByAngleY(value_type angle) noexcept {
- const value_type halfAngle = 0.5f * angle;
+ const value_type halfAngle = half * angle;
return rotateByAngleY(std::sin(halfAngle), std::cos(halfAngle));
}
/** Rotate this quaternion around Y axis with the given angle's sin + cos values */
@@ -412,7 +412,7 @@ class alignas(Value_type) Quaternion {
* @return this quaternion for chaining.
*/
constexpr_cxx26 Quaternion& rotateByAngleZ(value_type angle) noexcept {
- const value_type halfAngle = 0.5f * angle;
+ const value_type halfAngle = half * angle;
return rotateByAngleZ(std::sin(halfAngle), std::cos(halfAngle));
}
/** Rotate this quaternion around Y axis with the given angle's sin + cos values */
@@ -514,20 +514,20 @@ class alignas(Value_type) Quaternion {
+ x_x * vecX
- z_z * vecX
- y_y * vecX
- + 2.0f * ( m_y*m_w*vecZ - m_z*m_w*vecY + m_y*m_x*vecY + m_z*m_x*vecZ );
+ + two * ( m_y*m_w*vecZ - m_z*m_w*vecY + m_y*m_x*vecY + m_z*m_x*vecZ );
;
out.y = y_y * vecY
- z_z * vecY
+ w_w * vecY
- x_x * vecY
- + 2.0f * ( m_x*m_y*vecX + m_z*m_y*vecZ + m_w*m_z*vecX - m_x*m_w*vecZ );
+ + two * ( m_x*m_y*vecX + m_z*m_y*vecZ + m_w*m_z*vecX - m_x*m_w*vecZ );
out.z = z_z * vecZ
- y_y * vecZ
- x_x * vecZ
+ w_w * vecZ
- + 2.0f * ( m_x*m_z*vecX + m_y*m_z*vecY - m_w*m_y*vecX + m_w*m_x*vecY );
+ + two * ( m_x*m_z*vecX + m_y*m_z*vecY - m_w*m_y*vecX + m_w*m_x*vecY );
}
return out;
}
@@ -547,9 +547,9 @@ class alignas(Value_type) Quaternion {
*/
constexpr_cxx26 Quaternion& setSlerp(const Quaternion& a, const Quaternion& b, const value_type changeAmnt) noexcept {
// std::cerr << "Slerp.0: A " << a << ", B " << b << ", t " << changeAmnt << std::endl;
- if (changeAmnt == 0.0f) {
+ if (changeAmnt == zero) {
*this = a;
- } else if (changeAmnt == 1.0f) {
+ } else if (changeAmnt == one) {
*this = b;
} else {
value_type bx = b.m_x;
@@ -564,34 +564,34 @@ class alignas(Value_type) Quaternion {
if( cosHalfTheta >= 0.95f ) {
// quaternions are close, just use linear interpolation
- scale0 = 1.0f - changeAmnt;
+ scale0 = one - changeAmnt;
scale1 = changeAmnt;
} else if ( cosHalfTheta <= -0.99f ) {
// the quaternions are nearly opposite,
// we can pick any axis normal to a,b to do the rotation
- scale0 = 0.5f;
- scale1 = 0.5f;
+ scale0 = half;
+ scale1 = half;
} else {
if( cosHalfTheta <= -std::numeric_limits<value_type>::epsilon() ) { // FIXME: .. or shall we use the upper bound 'cosHalfTheta < EPSILON' ?
// Negate the second quaternion and the result of the dot product (Inversion)
- bx *= -1.0f;
- by *= -1.0f;
- bz *= -1.0f;
- bw *= -1.0f;
- cosHalfTheta *= -1.0f;
+ bx *= -one;
+ by *= -one;
+ bz *= -one;
+ bw *= -one;
+ cosHalfTheta *= -one;
}
const value_type halfTheta = std::acos(cosHalfTheta);
- const value_type sinHalfTheta = std::sqrt(1.0f - cosHalfTheta*cosHalfTheta);
+ const value_type sinHalfTheta = std::sqrt(one - cosHalfTheta*cosHalfTheta);
// if theta = 180 degrees then result is not fully defined
// we could rotate around any axis normal to qa or qb
if ( std::abs(sinHalfTheta) < 0.001f ){ // fabs is floating point absolute
- scale0 = 0.5f;
- scale1 = 0.5f;
+ scale0 = half;
+ scale1 = half;
// throw new InternalError("XXX"); // FIXME should not be reached due to above inversion ?
} else {
// Calculate the scale for q1 and q2, according to the angle and
// it's sine value
- scale0 = std::sin((1.0f - changeAmnt) * halfTheta) / sinHalfTheta;
+ scale0 = std::sin((one - changeAmnt) * halfTheta) / sinHalfTheta;
scale1 = std::sin(changeAmnt * halfTheta) / sinHalfTheta;
}
}
@@ -679,11 +679,11 @@ class alignas(Value_type) Quaternion {
return setIdentity();
} else {
const value_type dot = v1.dot(v2) / factor; // normalize
- const value_type theta = std::acos(std::max(-1.0f, std::min(dot, 1.0f))); // clipping [-1..1]
+ const value_type theta = std::acos(std::max(-one, std::min(dot, one))); // clipping [-1..1]
Vec3 tmpPivotVec = v1.cross(v2);
- if ( dot < 0.0f && jau::is_zero( tmpPivotVec.length() ) ) {
+ if ( dot < zero && jau::is_zero( tmpPivotVec.length() ) ) {
// Vectors parallel and opposite direction, therefore a rotation of 180 degrees about any vector
// perpendicular to this vector will rotate vector a onto vector b.
//
@@ -704,7 +704,7 @@ class alignas(Value_type) Quaternion {
}
tmpPivotVec[dominantIndex] = -v1[ (dominantIndex + 1) % 3 ];
tmpPivotVec[(dominantIndex + 1) % 3] = v1[ dominantIndex ];
- tmpPivotVec[(dominantIndex + 2) % 3] = 0.0f;
+ tmpPivotVec[(dominantIndex + 2) % 3] = zero;
}
return setFromAngleAxis(theta, tmpPivotVec);
}
@@ -733,11 +733,11 @@ class alignas(Value_type) Quaternion {
return setIdentity();
} else {
const value_type dot = v1.dot(v2) / factor; // normalize
- const value_type theta = std::acos(std::max(-1.0f, std::min(dot, 1.0f))); // clipping [-1..1]
+ const value_type theta = std::acos(std::max(-one, std::min(dot, one))); // clipping [-1..1]
Vec3 tmpPivotVec = v1.cross(v2);
- if ( dot < 0.0f && jau::is_zero( tmpPivotVec.length() ) ) {
+ if ( dot < zero && jau::is_zero( tmpPivotVec.length() ) ) {
// Vectors parallel and opposite direction, therefore a rotation of 180 degrees about any vector
// perpendicular to this vector will rotate vector a onto vector b.
//
@@ -758,7 +758,7 @@ class alignas(Value_type) Quaternion {
}
tmpPivotVec[dominantIndex] = -v1[ (dominantIndex + 1) % 3 ];
tmpPivotVec[(dominantIndex + 1) % 3] = v1[ dominantIndex ];
- tmpPivotVec[(dominantIndex + 2) % 3] = 0.0f;
+ tmpPivotVec[(dominantIndex + 2) % 3] = zero;
}
return setFromAngleNormalAxis(theta, tmpPivotVec);
}
@@ -802,7 +802,7 @@ class alignas(Value_type) Quaternion {
if( vector.is_zero() ) {
setIdentity();
} else {
- const value_type halfangle = angle * 0.5f;
+ const value_type halfangle = angle * half;
const value_type sin = std::sin(halfangle);
m_x = vector.x * sin;
m_y = vector.y * sin;
@@ -823,11 +823,11 @@ class alignas(Value_type) Quaternion {
const value_type sqrLength = m_x*m_x + m_y*m_y + m_z*m_z;
value_type angle;
if ( jau::is_zero(sqrLength) ) { // length is ~0
- angle = 0.0f;
- axis.set( 1.0f, 0.0f, 0.0f );
+ angle = zero;
+ axis.set( one, zero, zero );
} else {
- angle = std::acos(m_w) * 2.0f;
- const value_type invLength = 1.0f / std::sqrt(sqrLength);
+ angle = std::acos(m_w) * two;
+ const value_type invLength = one / std::sqrt(sqrLength);
axis.set( m_x * invLength,
m_y * invLength,
m_z * invLength );
@@ -885,13 +885,13 @@ class alignas(Value_type) Quaternion {
if ( jau::is_zero3f(bankX, headingY, attitudeZ) ) {
return setIdentity();
} else {
- value_type angle = headingY * 0.5f;
+ value_type angle = headingY * half;
const value_type sinHeadingY = std::sin(angle);
const value_type cosHeadingY = std::cos(angle);
- angle = attitudeZ * 0.5f;
+ angle = attitudeZ * half;
const value_type sinAttitudeZ = std::sin(angle);
const value_type cosAttitudeZ = std::cos(angle);
- angle = bankX * 0.5f;
+ angle = bankX * half;
const value_type sinBankX = std::sin(angle);
const value_type cosBankX = std::cos(angle);
@@ -933,17 +933,17 @@ class alignas(Value_type) Quaternion {
const value_type test = m_x*m_y + m_z*m_w;
if (test > 0.499f * unit) { // singularity at north pole
- return Vec3( 0.0f, // m_x-bank
- 2.0f * std::atan2(m_x, m_w), // y-heading
+ return Vec3( zero, // m_x-bank
+ two * std::atan2(m_x, m_w), // y-heading
M_PI_2 ); // z-attitude
} else if (test < -0.499f * unit) { // singularity at south pole
- return Vec3( 0.0f, // m_x-bank
- -2.0 * std::atan2(m_x, m_w), // m_y-heading
+ return Vec3( zero, // m_x-bank
+ -two * std::atan2(m_x, m_w), // m_y-heading
-M_PI_2 ); // m_z-attitude
} else {
- return Vec3( std::atan2(2.0f * m_x * m_w - 2.0f * m_y * m_z, -sqx + sqy - sqz + sqw), // m_x-bank
- std::atan2(2.0f * m_y * m_w - 2.0f * m_x * m_z, sqx - sqy - sqz + sqw), // m_y-heading
- std::asin( 2.0f * test / unit) ); // z-attitude
+ return Vec3( std::atan2(two * m_x * m_w - two * m_y * m_z, -sqx + sqy - sqz + sqw), // m_x-bank
+ std::atan2(two * m_y * m_w - two * m_x * m_z, sqx - sqy - sqz + sqw), // m_y-heading
+ std::asin( two * test / unit) ); // z-attitude
}
}
@@ -968,27 +968,27 @@ class alignas(Value_type) Quaternion {
// The trace T is the sum of the diagonal elements; see
// http://mathworld.wolfram.com/MatrixTrace.html
- const value_type T = m00 + m11 + m22 + 1.0f;
- if ( T > 0.0f ) {
- const value_type S = 0.5f / std::sqrt(T); // S = 1 / ( 2 t )
+ const value_type T = m00 + m11 + m22 + one;
+ if ( T > zero ) {
+ const value_type S = half / std::sqrt(T); // S = 1 / ( 2 t )
m_w = 0.25f / S; // m_w = 1 / ( 4 S ) = t / 2
m_x = ( m21 - m12 ) * S;
m_y = ( m02 - m20 ) * S;
m_z = ( m10 - m01 ) * S;
} else if ( m00 > m11 && m00 > m22) {
- const value_type S = 0.5f / std::sqrt(1.0f + m00 - m11 - m22); // S=4*qx
+ const value_type S = half / std::sqrt(one + m00 - m11 - m22); // S=4*qx
m_w = ( m21 - m12 ) * S;
m_x = 0.25f / S;
m_y = ( m10 + m01 ) * S;
m_z = ( m02 + m20 ) * S;
} else if ( m11 > m22 ) {
- const value_type S = 0.5f / std::sqrt(1.0f + m11 - m00 - m22); // S=4*qy
+ const value_type S = half / std::sqrt(one + m11 - m00 - m22); // S=4*qy
m_w = ( m02 - m20 ) * S;
m_x = ( m20 + m01 ) * S;
m_y = 0.25f / S;
m_z = ( m21 + m12 ) * S;
} else {
- const value_type S = 0.5f / std::sqrt(1.0f + m22 - m00 - m11); // S=4*qz
+ const value_type S = half / std::sqrt(one + m22 - m00 - m11); // S=4*qz
m_w = ( m10 - m01 ) * S;
m_x = ( m02 + m20 ) * S;
m_y = ( m21 + m12 ) * S;
@@ -1066,10 +1066,10 @@ class alignas(Value_type) Quaternion {
return m;
}
value_type srecip;
- if ( jau::equals(1.0f, norm) ) {
- srecip = 2.0f;
+ if ( jau::equals(one, norm) ) {
+ srecip = two;
} else {
- srecip = 2.0f / norm;
+ srecip = two / norm;
}
const value_type x = m_x;
const value_type y = m_y;
@@ -1090,23 +1090,23 @@ class alignas(Value_type) Quaternion {
const value_type zz = z * zs;
const value_type zw = zs * w;
- m.m00 = 1.0f - ( yy + zz );
+ m.m00 = one - ( yy + zz );
m.m01 = ( xy - zw );
m.m02 = ( xz + yw );
- m.m03 = 0.0f;
+ m.m03 = zero;
m.m10 = ( xy + zw );
- m.m11 = 1.0f - ( xx + zz );
+ m.m11 = one - ( xx + zz );
m.m12 = ( yz - xw );
- m.m13 = 0.0f;
+ m.m13 = zero;
m.m20 = ( xz - yw );
m.m21 = ( yz + xw );
- m.m22 = 1.0f - ( xx + yy );
- m.m23 = 0.0f;
+ m.m22 = one - ( xx + yy );
+ m.m23 = zero;
- m.m30 = m.m31 = m.m32 = 0.0f;
- m.m33 = 1.0f;
+ m.m30 = m.m31 = m.m32 = zero;
+ m.m33 = one;
return m;
}
diff --git a/include/jau/mp/big_int.hpp b/include/jau/mp/big_int.hpp
index 3823e59..3d5cc5f 100644
--- a/include/jau/mp/big_int.hpp
+++ b/include/jau/mp/big_int.hpp
@@ -599,7 +599,7 @@ namespace jau::mp {
*
* @param e the exponent
*/
- BigInt mod_pow(BigInt e, BigInt m) {
+ BigInt mod_pow(BigInt e, const BigInt& m) {
const BigInt& b = *this;
if( b.is_zero() ) {
return BigInt::zero();
@@ -678,7 +678,7 @@ namespace jau::mp {
const big_int_t& max); // TODO
*/
- std::string to_dec_string(bool add_details=false) const noexcept {
+ std::string to_dec_string(bool add_details=false) const {
// Use the largest power of 10 that fits in a mp_word_t
mp_word_t conversion_radix, radix_digits;
if constexpr ( 64 == mp_word_bits ) {
@@ -690,7 +690,7 @@ namespace jau::mp {
}
// (over-)estimate of the number of digits needed; log2(10) ~ 3.3219
- const size_t digit_estimate = static_cast<size_t>(1 + (this->bits() / 3.32));
+ const size_t digit_estimate = static_cast<size_t>(1 + (static_cast<double>(this->bits()) / 3.32));
// (over-)estimate of db such that conversion_radix^db > *this
const size_t digit_blocks = (digit_estimate + radix_digits - 1) / radix_digits;
@@ -738,8 +738,8 @@ namespace jau::mp {
}
// Reverse and convert to textual digits
- for(auto i = digits.rbegin(); i != digits.rend(); ++i) {
- s.push_back(*i + '0'); // assumes ASCII
+ for(uint8_t d : digits) {
+ s.push_back(static_cast<char>(d + '0')); // assumes ASCII
}
if(s.empty()) {
@@ -1088,7 +1088,7 @@ namespace jau::mp {
// This could be made faster using the same trick as to_dec_string
for(size_t i = 0; i < str_len; ++i) {
- const char c = buf[i];
+ const char c = static_cast<char>(buf[i]);
if(c < '0' || c > '9') {
throw jau::math::MathDomainError("invalid decimal char", E_FILE_LINE);
@@ -1556,8 +1556,8 @@ namespace jau {
* @{
*/
- inline mp::BigInt abs(mp::BigInt x) noexcept { return x.abs(); }
- inline mp::BigInt pow(mp::BigInt b, mp::BigInt e) { return b.pow(e); }
+ inline mp::BigInt abs(const mp::BigInt& x) noexcept { return x.abs(); }
+ inline mp::BigInt pow(mp::BigInt b, const mp::BigInt& e) { return b.pow(e); }
inline const mp::BigInt& min(const mp::BigInt& x, const mp::BigInt& y) noexcept {
return x < y ? x : y;
diff --git a/include/jau/os/dyn_linker.hpp b/include/jau/os/dyn_linker.hpp
index db6b6d5..d219ea1 100644
--- a/include/jau/os/dyn_linker.hpp
+++ b/include/jau/os/dyn_linker.hpp
@@ -70,8 +70,8 @@ namespace jau::os {
std::string m_name;
ssize_t m_count;
public:
- LibRef(const std::string& name) noexcept
- : m_name(name), m_count(1) {}
+ LibRef(std::string name) noexcept
+ : m_name(std::move(name)), m_count(1) {}
constexpr_cxx20 LibRef(const LibRef& o) noexcept = default;
constexpr_cxx20 LibRef(LibRef&& o) noexcept = default;
diff --git a/include/jau/os/func_resolver.hpp b/include/jau/os/func_resolver.hpp
index 779c090..5273b09 100644
--- a/include/jau/os/func_resolver.hpp
+++ b/include/jau/os/func_resolver.hpp
@@ -54,7 +54,7 @@ namespace jau::os {
* Queries whether function 'funcName' is available.
*/
bool isFunctionAvailable(const std::string& funcName) const noexcept {
- return 0 != dynamicLookupFunction(funcName);
+ return nullptr != dynamicLookupFunction(funcName);
}
};
diff --git a/include/jau/os/native_lib.hpp b/include/jau/os/native_lib.hpp
index 37ea7eb..27a34f0 100644
--- a/include/jau/os/native_lib.hpp
+++ b/include/jau/os/native_lib.hpp
@@ -23,10 +23,8 @@
*/
#pragma once
-#include <cstdint>
#include <string>
-#include "jau/debug.hpp"
#include "jau/string_util.hpp"
#include "jau/os/func_resolver.hpp"
@@ -194,7 +192,7 @@ namespace jau::os {
} else {
res = m_dynLink.openLibraryLocal(path);
}
- if ( 0 != res ) {
+ if ( nullptr != res ) {
NativeLibrary nl(m_dynLink, res, path, global, symbolName);
DBG_PRINT("NativeLibrary.open: Opened: %s", nl.toString().c_str());
return nl;
diff --git a/include/jau/string_util.hpp b/include/jau/string_util.hpp
index cd12758..14b0a11 100644
--- a/include/jau/string_util.hpp
+++ b/include/jau/string_util.hpp
@@ -144,7 +144,7 @@ namespace jau {
inline std::string to_hexstring(value_type const & v) noexcept
{
const uintptr_t v2 = reinterpret_cast<uintptr_t>(v);
- return bytesHexString(pointer_cast<const uint8_t*>(&v2), 0, sizeof(v), false /* lsbFirst */);
+ return bytesHexString(pointer_cast<const uint8_t*>(&v2), 0, sizeof(v), false /* lsbFirst */); // NOLINT(bugprone-sizeof-expression): Intended
}
/**
@@ -271,7 +271,7 @@ namespace jau {
bool> = true>
inline std::string to_string(const value_type & ref)
{
- return to_hexstring((void*)ref);
+ return to_hexstring((void*)ref); // NOLINT(bugprone-multi-level-implicit-pointer-conversion)
}
template< class value_type,
diff --git a/include/jau/token_fsm.hpp b/include/jau/token_fsm.hpp
index f54bf5e..a2e2ed2 100644
--- a/include/jau/token_fsm.hpp
+++ b/include/jau/token_fsm.hpp
@@ -224,8 +224,10 @@ namespace jau::lang {
/**
* token_error value, denoting an invalid token or alphabet code-point.
*/
- static inline constexpr const uint_t token_error = std::numeric_limits<uint_t>::max();
+ constexpr static const uint_t token_error = std::numeric_limits<uint_t>::max();
+ constexpr static uint_t to_symbol(char c) noexcept { return static_cast<unsigned char>(c); }
+
/**
* Terminal token name and ASCII string value pair, provided by user.
*/
@@ -373,7 +375,7 @@ namespace jau::lang {
* @param tkey_word the given token name and value pair
* @return true if successful, otherwise false
*/
- bool add(const token_value_t& tkey_word) noexcept {
+ bool add(const token_value_t& tkey_word) {
if( 0 == tkey_word.name || token_error == tkey_word.name ) {
// invalid token name
return false;
@@ -397,7 +399,7 @@ namespace jau::lang {
++char_num
)
{
- c = key_word[char_num];
+ c = to_symbol(key_word[char_num]);
JAU_TRACE_PRINT(" [%c, ", (char)c);
if( is_separator( c ) ) {
@@ -481,7 +483,7 @@ namespace jau::lang {
if( i2 == haystack.size() ) {
// position after token end
c = m_end;
- } else if( is_separator( c = haystack[i2++] ) ) {
+ } else if( is_separator( c = to_symbol( haystack[i2++] ) ) ) {
i2--; // position after token end
c = m_end;
} else {
@@ -532,7 +534,7 @@ namespace jau::lang {
if( i2 == word.size() ) {
c = m_end;
} else {
- c = word[i2++];
+ c = to_symbol( word[i2++] );
const alphabet::code_point_t cp = m_alphabet.code_point(c);
if( alphabet::code_error == cp ) {
c = token_error;
diff --git a/include/jau/type_traits_queries.hpp b/include/jau/type_traits_queries.hpp
index 068a701..f3f9616 100644
--- a/include/jau/type_traits_queries.hpp
+++ b/include/jau/type_traits_queries.hpp
@@ -226,7 +226,7 @@ namespace jau {
}
};
#define JAU_TYPENAME_CUE(A) template<> struct jau::type_name_cue<A> { static const char * name() { return #A; } };
- #define JAU_TYPENAME_CUE_ALL(A) JAU_TYPENAME_CUE(A) JAU_TYPENAME_CUE(A*) JAU_TYPENAME_CUE(const A*) JAU_TYPENAME_CUE(A&) JAU_TYPENAME_CUE(const A&)
+ #define JAU_TYPENAME_CUE_ALL(A) JAU_TYPENAME_CUE(A) JAU_TYPENAME_CUE(A*) JAU_TYPENAME_CUE(const A*) JAU_TYPENAME_CUE(A&) JAU_TYPENAME_CUE(const A&) // NOLINT(bugprone-macro-parentheses)
/**
// *************************************************
@@ -330,13 +330,13 @@ namespace jau {
#define METHOD_CHECKER(checker, name, ret, args) \
template<class C, typename=void> struct checker : std::false_type {}; \
template<class C> struct checker<C, typename std::enable_if_t< \
- std::is_convertible_v<decltype(std::declval<C>().name args), ret>>> : std::true_type {};
+ std::is_convertible_v<decltype(std::declval<C>().name args), ret>>> : std::true_type {}; // NOLINT(bugprone-macro-parentheses)
/// Checker for member function with exact retutn type and accepting given arguments
#define METHOD_CHECKER_STRICT_RET(name, fn, ret, args) \
template<class C, typename=void> struct name : std::false_type {}; \
template<class C> struct name<C, typename std::enable_if_t< \
- std::is_same_v<decltype(std::declval<C>().fn args), ret>>> : std::true_type {};
+ std::is_same_v<decltype(std::declval<C>().fn args), ret>>> : std::true_type {}; // NOLINT(bugprone-macro-parentheses)
/// Checker for member function accepting given arguments
#define METHOD_CHECKER_ANY(name, fn, args) \
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e54c6f2..42eacff 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -9,8 +9,8 @@ include_directories(
)
set (jaulib_LIB_SRCS
- basic_types.cpp
base_codec.cpp
+ basic_types.cpp
byte_stream.cpp
cpuid.cpp
debug.cpp
diff --git a/test/test_eui48.cpp b/test/test_eui48.cpp
index ef59ac3..c978f14 100644
--- a/test/test_eui48.cpp
+++ b/test/test_eui48.cpp
@@ -19,7 +19,7 @@ static void test_sub01(const lb_endian_t byte_order, const std::string& mac_str,
PRAGMA_DISABLE_WARNING_PUSH
PRAGMA_DISABLE_WARNING_RESTRICT
// bogus gcc 12.2 'may overlap'
- jau::for_each_const(mac_sub_strs, [&byte_order, &i, &mac, &indices](const std::string &mac_sub_str) {
+ jau::for_each_const(mac_sub_strs, [&byte_order, &i, &mac, &indices](const std::string &mac_sub_str) noexcept { // NOLINT(bugprone-exception-escape)
const EUI48Sub mac_sub(mac_sub_str);
printf("EUI48Sub mac02_sub: '%s' -> '%s'\n", mac_sub_str.c_str(), mac_sub.toString().c_str());
{