summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt10
-rw-r--r--test.cc140
-rw-r--r--zp/include/zp/mth4
3 files changed, 90 insertions, 64 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index b877304..c5d63ec 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -181,6 +181,13 @@
* Fix urch not being renamed to unrch in C++;
* Remove constant mathematical functions;
+* Fix isnan not being present in C++ API;
+* Fix prefixes and sufixes being present on C++ objects;
+
+* Fix changelog;
+* Add more math tests;
+* Implement C++ isnan;
+
# 0.0.2
* Migrate to CMake;
@@ -196,9 +203,6 @@
* Add installation script;
* Update gitignore;
-* Fix isnan not being present in C++ API;
-* Fix prefixes and sufixes being present on C++ objects;
-
# 0.0.1
* Fix unused parameter and invalid invocation in overload of srh;
diff --git a/test.cc b/test.cc
index 77185f5..b25ff2d 100644
--- a/test.cc
+++ b/test.cc
@@ -9,8 +9,8 @@
#include <zp/mth>
#include <zp/str>
-#if !zp_std_cxx11
-#error At least C++11 is required for this test!
+#if !zp_std_cxx17
+#error At least C++17 is required for this test!
#endif
static_assert(::zp::isptr<int>::val == false);
@@ -34,14 +34,14 @@ static_assert(::zp::isptr<int const volatile * const volatile>::val == true);
static_assert(::zp::typequ<int,int>::val == true);
static_assert(::zp::typequ<int,long>::val == false);
-static_assert(::zp::typequ<::zp::i8, ::std::uint_least8_t>::val == true);
-static_assert(::zp::typequ<::zp::i8s, ::std::int_least8_t>::val == true);
-static_assert(::zp::typequ<::zp::i01, ::std::uint_least16_t>::val == true);
-static_assert(::zp::typequ<::zp::i01s,::std::int_least16_t>::val == true);
-static_assert(::zp::typequ<::zp::i02, ::std::uint_least32_t>::val == true);
-static_assert(::zp::typequ<::zp::i02s,::std::int_least32_t>::val == true);
-static_assert(::zp::typequ<::zp::i04, ::std::uint_least64_t>::val == true);
-static_assert(::zp::typequ<::zp::i04s,::std::int_least64_t>::val == true);
+static_assert(::zp::typequ<::zp::i8, ::std::uint8_t>::val == true);
+static_assert(::zp::typequ<::zp::i8s, ::std::int8_t>::val == true);
+static_assert(::zp::typequ<::zp::i01, ::std::uint16_t>::val == true);
+static_assert(::zp::typequ<::zp::i01s,::std::int16_t>::val == true);
+static_assert(::zp::typequ<::zp::i02, ::std::uint32_t>::val == true);
+static_assert(::zp::typequ<::zp::i02s,::std::int32_t>::val == true);
+static_assert(::zp::typequ<::zp::i04, ::std::uint64_t>::val == true);
+static_assert(::zp::typequ<::zp::i04s,::std::int64_t>::val == true);
static_assert(::zp::typequ<::zp::intptr,::std::uintptr_t>::val == true);
static_assert(::zp::typequ<::zp::siz, ::std::size_t>::val == true);
@@ -157,16 +157,16 @@ static_assert(::zp::maxval<long unsigned>::val == ::std::numeric_limits<lon
static_assert(::zp::maxval<long long unsigned>::val == ::std::numeric_limits<long long unsigned>::max());
static_assert(::zp::maxval<wchar_t>::val == ::std::numeric_limits<wchar_t>::max());
-template<typename ltyp,typename rtyp> static auto cmp_eq(int unsigned & num,int unsigned & numerr,long const ln,ltyp const & lvalref,rtyp const & rvalref) noexcept {
+template<typename ltyp,typename rtyp> static auto cmp(int unsigned & num,int unsigned & numerr,long const ln,ltyp const & lvalref,rtyp const & rvalref) noexcept {
char const * const ltypnm = typeid (ltyp).name();
char const * const rtypnm = typeid (rtyp).name();
auto const getval = [](auto const & valref) {
- using typ = typename ::zp::remref<decltype (valref)>::typ;
+ using typ = typename ::zp::remqual<typename ::zp::remref<decltype (valref)>::typ>::typ;
if constexpr (::zp::ischrtyp<typ>::val) {return static_cast<::zp::i02>(valref);}
- else if constexpr (::zp::isptr<typ>::val) {return reinterpret_cast<void *>(valref);}
- else {return valref;}
+ else if constexpr (::zp::isptr<typ>::val) {return reinterpret_cast<void *>(valref);}
+ else {return valref;}
};
auto const lval = getval(lvalref);
@@ -185,7 +185,7 @@ template<typename ltyp,typename rtyp> static auto cmp_eq(int unsigned & num,int
::std::cout <<"\x1B[38;5;77mequal\x1B[0m\n";
}
-#define cmp_eq(lval,rval) (::cmp_eq(num,numerr,__LINE__,(lval),(rval)))
+#define cmp(lval,rval) (::cmp(num,numerr,__LINE__,(lval),(rval)))
int main() {
int unsigned num;
@@ -205,7 +205,7 @@ int main() {
::zp::opt<::zp::i8s> opt = ::zp::nulopt;
- cmp_eq(opt.chk(),false);
+ cmp(opt.chk(),false);
auto const fun = [](char const * msg) -> void {
::std::cout << msg << ::std::endl;
@@ -215,8 +215,30 @@ int main() {
opt = -0x45;
- cmp_eq(opt.chk(),true);
- cmp_eq(opt.exp(fun,"expectation failed"),-0x45);
+ cmp(opt.chk(),true);
+ cmp(opt.exp(fun,"expectation failed"),-0x45);
+ }();
+
+ [&] {
+ tst("mathematics");
+
+ ::zp::f02 f02;
+ ::zp::f04 f04;
+
+ cmp(sizeof (f02),0x4u);
+ cmp(sizeof (f04),0x8u);
+
+ f02 = ::zp::nan<::zp::f02>::val;
+ f04 = ::zp::nan<::zp::f04>::val;
+
+ cmp(::zp::isnan(f02),true);
+ cmp(::zp::isnan(f04),true);
+
+ f02 = ::zp::inf<::zp::f02>::val;
+ f04 = ::zp::inf<::zp::f04>::val;
+
+ cmp(f02 >= ::zp::maxval<::zp::f02>::val,true);
+ cmp(f04 >= ::zp::maxval<::zp::f04>::val,true);
}();
/*[&] {
@@ -230,7 +252,7 @@ int main() {
.x = +0x2,
.y = -0x4,
};
- cmp_eq(::zp::dot(lvec2,rvec2),0xE);
+ cmp(::zp::dot(lvec2,rvec2),0xE);
::zp::vec3<int> const lvec3 = {
.x = +0x1,
@@ -242,7 +264,7 @@ int main() {
.y = -0x4,
.z = +0x6,
};
- cmp_eq(::zp::dot(lvec3,rvec3),0x2C);
+ cmp(::zp::dot(lvec3,rvec3),0x2C);
::zp::vec4<int> const lvec4 = {
.x = +0x1,
@@ -256,22 +278,22 @@ int main() {
.z = +0x6,
.w = -0x8,
};
- cmp_eq(::zp::dot(lvec4,rvec4),0x64);
+ cmp(::zp::dot(lvec4,rvec4),0x64);
auto const avec2 = ::zp::vadd(lvec2,rvec2);
auto const svec2 = ::zp::vsub(lvec2,rvec2);
- cmp_eq(avec2.x,+0x3);
- cmp_eq(avec2.y,-0x7);
- cmp_eq(svec2.x,-0x1);
- cmp_eq(svec2.y,+0x1);
+ cmp(avec2.x,+0x3);
+ cmp(avec2.y,-0x7);
+ cmp(svec2.x,-0x1);
+ cmp(svec2.y,+0x1);
}();
[&] {
tst("special numbers");
- cmp_eq(zp_isnanf( zp_nanf), true);
- cmp_eq(zp_isnand( zp_nand), true);
- cmp_eq(zp_isnandl(zp_nanld),true);
+ cmp(zp_isnanf( zp_nanf), true);
+ cmp(zp_isnand( zp_nand), true);
+ cmp(zp_isnandl(zp_nanld),true);
}();*/
[&] {
@@ -279,19 +301,19 @@ int main() {
::zp::i04 filbuf;
- cmp_eq(::zp::memfil(&filbuf,0xFFu,0x8u),reinterpret_cast<char unsigned *>(&filbuf)+0x8u);
- cmp_eq(::zp::memfil(&filbuf,0x7Fu,0x4u),reinterpret_cast<char unsigned *>(&filbuf)+0x4u);
- cmp_eq(::zp::memfil(&filbuf,0x3Fu,0x2u),reinterpret_cast<char unsigned *>(&filbuf)+0x2u);
- cmp_eq(::zp::memfil(&filbuf,0x1Fu,0x1u),reinterpret_cast<char unsigned *>(&filbuf)+0x1u);
+ cmp(::zp::memfil(&filbuf,0xFFu,0x8u),reinterpret_cast<char unsigned *>(&filbuf)+0x8u);
+ cmp(::zp::memfil(&filbuf,0x7Fu,0x4u),reinterpret_cast<char unsigned *>(&filbuf)+0x4u);
+ cmp(::zp::memfil(&filbuf,0x3Fu,0x2u),reinterpret_cast<char unsigned *>(&filbuf)+0x2u);
+ cmp(::zp::memfil(&filbuf,0x1Fu,0x1u),reinterpret_cast<char unsigned *>(&filbuf)+0x1u);
- cmp_eq(filbuf,0xFFFFFFFF7F7F3F1Fu);
+ cmp(filbuf,0xFFFFFFFF7F7F3F1Fu);
::zp::i04 cpybuf;
::zp::memcpy(&cpybuf,&filbuf,0x8u);
- cmp_eq(cpybuf,filbuf);
+ cmp(cpybuf,filbuf);
- cmp_eq(::zp::memsrh(&cpybuf,0x1Fu,0x8u),reinterpret_cast<char unsigned *>(&cpybuf));
+ cmp(::zp::memsrh(&cpybuf,0x1Fu,0x8u),reinterpret_cast<char unsigned *>(&cpybuf));
}();
[&] {
@@ -305,17 +327,17 @@ int main() {
::zp::siz const wlen = ::zp_wstrlen( wstr);
::zp::siz const len02 = ::zp_utf32len(str02);
- cmp_eq(len, 0xCu);
- cmp_eq(wlen, 0xCu);
- cmp_eq(len02,0xCu);
+ cmp(len, 0xCu);
+ cmp(wlen, 0xCu);
+ cmp(len02,0xCu);
auto const buf = new char[ len];
auto const wbuf = new wchar_t[ wlen];
auto const buf02 = new char32_t[len02];
- cmp_eq(::zp_strcpy( buf, str), len);
- cmp_eq(::zp_wstrcpy( wbuf, wstr), wlen);
- cmp_eq(::zp_utf32cpy(buf02,str02),len02);
+ cmp(::zp_strcpy( buf, str), len);
+ cmp(::zp_wstrcpy( wbuf, wstr), wlen);
+ cmp(::zp_utf32cpy(buf02,str02),len02);
delete[] buf;
delete[] wbuf;
@@ -328,27 +350,27 @@ int main() {
char32_t const src[] = U"\U0001F480";
::zp::siz const buf8len = ::zp_utf8enclen(src);
- cmp_eq(buf8len,0x4u);
+ cmp(buf8len,0x4u);
::zp::c8 * buf8 = new ::zp::c8[buf8len+0x1];
::zp_utf8enc(buf8,src);
- cmp_eq(buf8[0x0],0xF0u);
- cmp_eq(buf8[0x1],0x9Fu);
- cmp_eq(buf8[0x2],0x92u);
- cmp_eq(buf8[0x3],0x80u);
- cmp_eq(buf8[0x4],0x00u);
+ cmp(buf8[0x0],0xF0u);
+ cmp(buf8[0x1],0x9Fu);
+ cmp(buf8[0x2],0x92u);
+ cmp(buf8[0x3],0x80u);
+ cmp(buf8[0x4],0x00u);
::zp::siz const buf02len = ::zp_utf8declen(buf8);
- cmp_eq(buf02len,0x1u);
+ cmp(buf02len,0x1u);
char32_t * buf02 = new char32_t[buf02len+0x1];
::zp_utf8dec(buf02,buf8);
- cmp_eq(buf02[0x0],0x1F480u);
- cmp_eq(buf02[0x1],0x0u);
+ cmp(buf02[0x0],0x1F480u);
+ cmp(buf02[0x1],0x0u);
delete[] buf8;
delete[] buf02;
@@ -360,27 +382,27 @@ int main() {
char32_t const src[] = U"\U0001F480\u00F0";
::zp::siz const buf01len = ::zp_utf16enclen(src);
- cmp_eq(buf01len,0x3u);
+ cmp(buf01len,0x3u);
char16_t * buf01 = new char16_t[buf01len+0x1];
::zp_utf16enc(buf01,src);
- cmp_eq(buf01[0x0],0xD83Du);
- cmp_eq(buf01[0x1],0xDC80u);
- cmp_eq(buf01[0x2],0x00F0u);
- cmp_eq(buf01[0x3],0x0000u);
+ cmp(buf01[0x0],0xD83Du);
+ cmp(buf01[0x1],0xDC80u);
+ cmp(buf01[0x2],0x00F0u);
+ cmp(buf01[0x3],0x0000u);
::zp::siz const buf02len = ::zp_utf16declen(buf01);
- cmp_eq(buf02len,0x2u);
+ cmp(buf02len,0x2u);
char32_t * buf02 = new char32_t[buf02len+0x1];
::zp_utf16dec(buf02,buf01);
- cmp_eq(buf02[0x0],0x1F480u);
- cmp_eq(buf02[0x1],0xF0u);
- cmp_eq(buf02[0x2],0x0u);
+ cmp(buf02[0x0],0x1F480u);
+ cmp(buf02[0x1],0xF0u);
+ cmp(buf02[0x2],0x0u);
delete[] buf01;
delete[] buf02;
diff --git a/zp/include/zp/mth b/zp/include/zp/mth
index 8de6bd4..4887c67 100644
--- a/zp/include/zp/mth
+++ b/zp/include/zp/mth
@@ -94,8 +94,8 @@ namespace zp {
zp_iln zp_nothw zp_unseq zp_useres inline ::zp::f02 exp(::zp::f02 val,::zp::f02 n);
zp_iln zp_nothw zp_unseq zp_useres inline ::zp::f04 exp(::zp::f04 val,::zp::f04 n);
- zp_iln zp_nothw zp_unseq zp_useres inline bool isnan(::zp::f02 val);
- zp_iln zp_nothw zp_unseq zp_useres inline bool isnan(::zp::f04 val);
+ zp_iln zp_nothw zp_unseq zp_useres inline bool isnan(::zp::f02 val) {return zp_isnanf02(val);}
+ zp_iln zp_nothw zp_unseq zp_useres inline bool isnan(::zp::f04 val) {return zp_isnanf04(val);}
zp_iln zp_nothw zp_unseq zp_useres inline ::zp::f02 lb(::zp::f02 val);
zp_iln zp_nothw zp_unseq zp_useres inline ::zp::f04 lb(::zp::f04 val);