Skip to content

Commit 406c670

Browse files
committed
some fixes
- added arithmetic_tests (except mat) - some fixes for gcc and clang compilers
1 parent 7830155 commit 406c670

File tree

20 files changed

+671
-60
lines changed

20 files changed

+671
-60
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,4 +410,5 @@ compile_commands.json
410410
CTestTestfile.cmake
411411
_deps
412412
CMakeUserPresets.json
413-
out
413+
out
414+
/third_party

CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.16)
2-
project(mstd VERSION 1.2 LANGUAGES CXX)
2+
project(mstd VERSION 1.2.0 LANGUAGES CXX)
33

44
option(MSTD_ENABLE_CXX20 OFF)
55

@@ -11,6 +11,10 @@ endif()
1111
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1212
set(CMAKE_CXX_EXTENSIONS OFF)
1313

14+
option(BUILD_MSTD_TESTS "Build mstd tests" OFF)
15+
16+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/third_party.cmake)
17+
1418
# header files
1519
set(PROJECT_HEADERS ${PROJECT_NAME}_HEADERS)
1620
set(BUILD_HEADERS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/include)
@@ -53,6 +57,12 @@ else()
5357
target_compile_definitions(${PROJECT_NAME} INTERFACE _MSTD_ENABLE_CXX20=0)
5458
endif()
5559

60+
message(STATUS "TESTS ${BUILD_MSTD_TESTS}")
61+
62+
if(BUILD_MSTD_TESTS)
63+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
64+
endif()
65+
5666
# TODO: install
5767

5868
# library installation

CMakeSettings.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
"installRoot": "${projectDir}\\out\\install\\${name}",
1010
"cmakeCommandArgs": "",
1111
"buildCommandArgs": "",
12-
"ctestCommandArgs": ""
12+
"ctestCommandArgs": "",
13+
"variables": [
14+
{
15+
"name": "BUILD_MSTD_TESTS",
16+
"value": "True",
17+
"type": "BOOL"
18+
}
19+
]
1320
},
1421
{
1522
"name": "x64-Release",

cmake/third_party.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# for CPM
2+
set(CPM_USE_LOCAL_PACKAGES OFF)
3+
4+
if(NOT CPM_SOURCE_CACHE)
5+
# Storage location
6+
set(CPM_SOURCE_CACHE ${CMAKE_SOURCE_DIR}/third_party)
7+
endif()
8+
9+
# Set download location
10+
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM.cmake")
11+
12+
# download CPM.cmake
13+
# Expand relative path. This is important if the provided path contains a tilde (~)
14+
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
15+
if(NOT EXISTS ${CPM_DOWNLOAD_LOCATION})
16+
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
17+
file(DOWNLOAD
18+
https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/CPM.cmake
19+
${CPM_DOWNLOAD_LOCATION}
20+
)
21+
endif()
22+
message(STATUS "Include CPM.cmake from ${CPM_DOWNLOAD_LOCATION}")
23+
include(${CPM_DOWNLOAD_LOCATION})
24+
25+
if(BUILD_MSTD_TESTS)
26+
CPMAddPackage("gh:google/googletest#release-1.11.0")
27+
if(googletest_ADDED)
28+
message(STATUS "Cmake added local googletest: ${googletest_SOURCE_DIR}")
29+
endif()
30+
endif()

include/arithmetic/mstd/arithmetic_libs.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
#include <bit>
1818
#include <iostream>
1919
#include <iomanip>
20-
#include "../../utils/mstd/types.hpp"
20+
#include <cstring>
21+
#include <string>
22+
#include <mstd/mstd_config.hpp>
23+
#include <mstd/types.hpp>

include/arithmetic/mstd/math_functions.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace mstd {
8080
return x - std::floor(x);
8181
}
8282
else {
83-
return x;
83+
return 0;
8484
}
8585
}
8686

include/arithmetic/mstd/overflow_operations.hpp

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@ namespace mstd {
1818
#endif
1919
static constexpr bool add_overflow(const _Na& a, const _Nb& b, _N& out) {
2020
if constexpr (are_unsigned_v<_N, _Na, _Nb>) {
21-
if (a > std::numeric_limits<_N>().max() - b) {
21+
if (a > std::numeric_limits<_N>::max() - b) {
2222
return true;
2323
}
2424
}
2525
else {
26-
const std::numeric_limits<_N>& limit = std::numeric_limits<_N>();
27-
28-
if (b >= 0 && a > limit.max() - b) {
26+
if (b >= 0 && a > std::numeric_limits<_N>::max() - b) {
2927
return true;
3028
}
3129

32-
if (b <= 0 && a < limit.min() - b) {
30+
if (b <= 0 && a < std::numeric_limits<_N>::min() - b) {
3331
return true;
3432
}
3533
}
@@ -45,18 +43,16 @@ namespace mstd {
4543
#endif
4644
static constexpr bool sub_overflow(const _Na& a, const _Nb& b, _N& out) {
4745
if constexpr (are_unsigned_v<_N, _Na, _Nb>) {
48-
if (a < std::numeric_limits<_N>().min() + b) {
46+
if (a < std::numeric_limits<_N>::min() + b) {
4947
return true;
5048
}
5149
}
5250
else {
53-
const std::numeric_limits<_N>& limit = std::numeric_limits<_N>();
54-
55-
if (b <= 0 && a > limit.max() + b) {
51+
if (b <= 0 && a > std::numeric_limits<_N>::max() + b) {
5652
return true;
5753
}
5854

59-
if (b >= 0 && a < limit.min() + b) {
55+
if (b >= 0 && a < std::numeric_limits<_N>::min() + b) {
6056
return true;
6157
}
6258
}
@@ -72,29 +68,25 @@ namespace mstd {
7268
#endif
7369
static constexpr bool mul_overflow(const _Na& a, const _Nb& b, _N& out) {
7470
if constexpr (are_unsigned_v<_N, _Na, _Nb>) {
75-
if (a != 0 && b != 0 && a > std::numeric_limits<_N>().max() / b) {
71+
if (a != 0 && b != 0 && a > std::numeric_limits<_N>::max() / b) {
7672
return true;
7773
}
7874
}
7975
else {
80-
const std::numeric_limits<_N>& limit = std::numeric_limits<_N>();
81-
const _N& min = limit.min();
82-
const _N& max = limit.max();
83-
8476
if (a != 0 && b != 0) {
85-
if (a == -1 && b == min) {
77+
if (a == -1 && b == std::numeric_limits<_N>::min()) {
8678
return true;
8779
}
8880

89-
if (a == min && b == -1) {
81+
if (a == std::numeric_limits<_N>::min() && b == -1) {
9082
return true;
9183
}
9284

93-
if (a > max / b) {
85+
if (a > std::numeric_limits<_N>::max() / b) {
9486
return true;
9587
}
9688

97-
if (a < min / b) {
89+
if (a < std::numeric_limits<_N>::min() / b) {
9890
return true;
9991
}
10092
}
@@ -111,18 +103,14 @@ namespace mstd {
111103
#endif
112104
static constexpr bool div_overflow(const _Na& a, const _Nb& b, _N& out) {
113105
if constexpr (are_unsigned_v<_N, _Na, _Nb>) {
114-
out = b == 0 ? std::numeric_limits<_N>().max() : a / b;
106+
out = b == 0 ? std::numeric_limits<_N>::max() : a / b;
115107
}
116108
else {
117-
const std::numeric_limits<_N>& limit = std::numeric_limits<_N>();
118-
const _N& min = limit.min();
119-
const _N& max = limit.max();
120-
121-
if (a == min && b == -1) {
109+
if (a == std::numeric_limits<_N>::min() && b == -1) {
122110
return true;
123111
}
124112

125-
out = b == 0 ? (a < 0 ? min : max) : a / b;
113+
out = b == 0 ? (a < 0 ? std::numeric_limits<_N>::min() : std::numeric_limits<_N>::max()) : a / b;
126114
}
127115
return false;
128116
}

include/arithmetic/mstd/quat.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,24 @@ namespace mstd {
246246
}
247247
quat<T>& operator--() {
248248
s -= 1;
249-
v--;
249+
--v;
250250
return *this;
251251
}
252+
quat<T> operator--(int) {
253+
quat<T> old = *this;
254+
operator--();
255+
return old;
256+
}
252257
quat<T>& operator++() {
253258
s += 1;
254-
v++;
259+
++v;
255260
return *this;
256261
}
262+
quat<T> operator++(int) {
263+
quat<T> old = *this;
264+
operator++();
265+
return old;
266+
}
257267

258268
bool operator==(const quat<T>& other) const {
259269
return s == other.s && v == other.v;

include/arithmetic/mstd/vec.hpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ namespace mstd {
438438
}
439439

440440
vec<N, T> refracted(const vec<N, T>& normal, const T& eta) const {
441-
float cos_theta = std::min(dot(-(*this), normal), 1.0f);
441+
float cos_theta = std::min((-(*this)).dot(normal), 1.0f);
442442
vec<N, T> r_out_perp = eta * (*this + cos_theta * normal);
443443
float length = r_out_perp.length();
444444
vec<N, T> r_out_parallel = -std::sqrt(std::abs(1.0f - length * length)) * normal;
@@ -447,7 +447,7 @@ namespace mstd {
447447

448448
vec<N, T>& saturate() noexcept {
449449
for (size_t i = 0; i != N; ++i) {
450-
_values[i] = saturate(_values[i]);
450+
_values[i] = ::mstd::saturate(_values[i]);
451451
}
452452
return *this;
453453
}
@@ -459,7 +459,7 @@ namespace mstd {
459459

460460
vec<N, T>& fract() noexcept {
461461
for (size_t i = 0; i != N; ++i) {
462-
_values[i] = fract(_values[i]);
462+
_values[i] = ::mstd::fract(_values[i]);
463463
}
464464
return *this;
465465
}
@@ -543,14 +543,14 @@ namespace mstd {
543543

544544
vec<N, T>& step(const T& edge) noexcept {
545545
for (size_t i = 0; i != N; ++i) {
546-
_values[i] = step(edge, _values[i]);
546+
_values[i] = ::mstd::step(edge, _values[i]);
547547
}
548548
return *this;
549549
}
550550

551551
vec<N, T>& step(const vec<N, T>& edge) noexcept {
552552
for (size_t i = 0; i != N; ++i) {
553-
_values[i] = step(edge[i], _values[i]);
553+
_values[i] = ::mstd::step(edge[i], _values[i]);
554554
}
555555
return *this;
556556
}
@@ -721,9 +721,19 @@ namespace mstd {
721721
vec<N, T>& operator++() {
722722
return *this += vec<N, T>::one();
723723
}
724+
vec<N, T> operator++(int) {
725+
vec<N, T> old = *this;
726+
operator++();
727+
return old;
728+
}
724729
vec<N, T>& operator--() {
725730
return *this -= vec<N, T>::one();
726731
}
732+
vec<N, T> operator--(int) {
733+
vec<N, T> old = *this;
734+
operator--();
735+
return old;
736+
}
727737

728738
template<size_t ON>
729739
bool operator==(const vec<ON, T>& other) const {

include/containers/mstd/containers_libs.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
#include <unordered_map>
1414
#include <map>
1515
#include <initializer_list>
16-
#include <stdexcept>
16+
#include <stdexcept>
17+
#include <mstd/mstd_config.hpp>

0 commit comments

Comments
 (0)