@@ -25,7 +25,7 @@ | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
/* This is OUR namespace. Don't let Windows headers fuck with it. */ | |||||
/* This is OUR namespace. Don't let Windows headers mess with it. */ | |||||
#undef min | #undef min | ||||
#undef max | #undef max | ||||
@@ -29,7 +29,7 @@ | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
/* This is OUR namespace. Don't let Windows headers fuck with it. */ | |||||
/* This is OUR namespace. Don't let Windows headers mess with it. */ | |||||
#undef min | #undef min | ||||
#undef max | #undef max | ||||
@@ -256,7 +256,8 @@ LOL_ATTR_NODISCARD static inline ldouble round(ldouble x) { return std::round(x) | |||||
LOL_ATTR_NODISCARD static inline T min(T x, T y) { return std::min(x, y); } \ | LOL_ATTR_NODISCARD static inline T min(T x, T y) { return std::min(x, y); } \ | ||||
LOL_ATTR_NODISCARD static inline T max(T x, T y) { return std::max(x, y); } \ | LOL_ATTR_NODISCARD static inline T max(T x, T y) { return std::max(x, y); } \ | ||||
LOL_ATTR_NODISCARD static inline T clamp(T x, T y, T z) { return min(max(x, y), z); } \ | LOL_ATTR_NODISCARD static inline T clamp(T x, T y, T z) { return min(max(x, y), z); } \ | ||||
LOL_ATTR_NODISCARD static inline T saturate(T x) { return min(max(x, (T)0), (T)1); } | |||||
LOL_ATTR_NODISCARD static inline T saturate(T x) { return min(max(x, (T)0), (T)1); } \ | |||||
LOL_ATTR_NODISCARD static inline T gcd(T x, T y) { return y == (T)0 ? lol::abs(x) : lol::gcd(y, lol::fmod(x, y)); } | |||||
#define LOL_GENERIC_FUNC_SIGNED(T) \ | #define LOL_GENERIC_FUNC_SIGNED(T) \ | ||||
LOL_GENERIC_FUNC(T) \ | LOL_GENERIC_FUNC(T) \ | ||||
@@ -24,7 +24,7 @@ | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
/* This is OUR namespace. Don't let Windows headers fuck with it. */ | |||||
/* This is OUR namespace. Don't let Windows headers mess with it. */ | |||||
#undef min | #undef min | ||||
#undef max | #undef max | ||||
@@ -24,7 +24,7 @@ | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
/* This is OUR namespace. Don't let Windows headers fuck with it. */ | |||||
/* This is OUR namespace. Don't let Windows headers mess with it. */ | |||||
#undef min | #undef min | ||||
#undef max | #undef max | ||||
@@ -37,7 +37,7 @@ test_math_SOURCES = test-common.cpp \ | |||||
math/cmplx.cpp math/half.cpp math/interp.cpp math/matrix.cpp \ | math/cmplx.cpp math/half.cpp math/interp.cpp math/matrix.cpp \ | ||||
math/quat.cpp math/rand.cpp math/real.cpp math/rotation.cpp \ | math/quat.cpp math/rand.cpp math/real.cpp math/rotation.cpp \ | ||||
math/trig.cpp math/vector.cpp math/polynomial.cpp math/noise/simplex.cpp \ | math/trig.cpp math/vector.cpp math/polynomial.cpp math/noise/simplex.cpp \ | ||||
math/bigint.cpp math/sqt.cpp | |||||
math/bigint.cpp math/sqt.cpp math/numbers.cpp | |||||
test_math_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/tools/lolunit | test_math_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/tools/lolunit | ||||
test_math_DEPENDENCIES = @LOL_DEPS@ | test_math_DEPENDENCIES = @LOL_DEPS@ | ||||
@@ -0,0 +1,44 @@ | |||||
// | |||||
// Lol Engine — Unit tests for number theory | |||||
// | |||||
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||||
// | |||||
// Lol Engine is free software. It comes without any warranty, to | |||||
// the extent permitted by applicable law. You can redistribute it | |||||
// and/or modify it under the terms of the Do What the Fuck You Want | |||||
// to Public License, Version 2, as published by the WTFPL Task Force. | |||||
// See http://www.wtfpl.net/ for more details. | |||||
// | |||||
#include <lol/engine-internal.h> | |||||
#include <lolunit.h> | |||||
namespace lol | |||||
{ | |||||
lolunit_declare_fixture(gcd_test) | |||||
{ | |||||
lolunit_declare_test(gcd_int) | |||||
{ | |||||
lolunit_assert_equal(1, lol::gcd(37, 600)); | |||||
lolunit_assert_equal(2, lol::gcd(4, 6)); | |||||
lolunit_assert_equal(2, lol::gcd(6, 4)); | |||||
lolunit_assert_equal(13, lol::gcd(13, 13)); | |||||
lolunit_assert_equal(20, lol::gcd(20, 100)); | |||||
lolunit_assert_equal(18913, lol::gcd(624129, 2061517)); | |||||
} | |||||
lolunit_declare_test(gcd_negative) | |||||
{ | |||||
lolunit_assert_equal(2, lol::gcd(4, -6)); | |||||
lolunit_assert_equal(2, lol::gcd(-4, 6)); | |||||
lolunit_assert_equal(2, lol::gcd(-4, -6)); | |||||
lolunit_assert_equal(2, lol::gcd(6, -4)); | |||||
lolunit_assert_equal(2, lol::gcd(-6, 4)); | |||||
lolunit_assert_equal(2, lol::gcd(-6, -4)); | |||||
} | |||||
}; | |||||
} /* namespace lol */ | |||||
@@ -42,6 +42,7 @@ | |||||
<ClCompile Include="math\interp.cpp" /> | <ClCompile Include="math\interp.cpp" /> | ||||
<ClCompile Include="math\matrix.cpp" /> | <ClCompile Include="math\matrix.cpp" /> | ||||
<ClCompile Include="math\noise\simplex.cpp" /> | <ClCompile Include="math\noise\simplex.cpp" /> | ||||
<ClCompile Include="math\numbers.cpp" /> | |||||
<ClCompile Include="math\polynomial.cpp" /> | <ClCompile Include="math\polynomial.cpp" /> | ||||
<ClCompile Include="math\quat.cpp" /> | <ClCompile Include="math\quat.cpp" /> | ||||
<ClCompile Include="math\rand.cpp" /> | <ClCompile Include="math\rand.cpp" /> | ||||