Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
edmond-chow authored Aug 26, 2023
1 parent e9d8c51 commit 361133e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ namespace ComplexTestingConsole
public:
static std::wstring GetTitle();
static std::wstring GetStartupLine();
static std::wstring GetSedenTitle();
static bool IsSwitchTo(const std::wstring& Str);
///
/// Main Thread
Expand Down
52 changes: 49 additions & 3 deletions C++/Sedenion Linux.rar/Sedenion/Sedenion/Sedenion.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <cmath>
#include <numbers>
#include <limits>
#include "Module.h"
#include "Cayley Dickson Algebra.h"
#pragma pack(push)
Expand All @@ -16,10 +17,55 @@
#define SEDEN_INTERFACE
#define SEDEN_FUNC_CALL
#define SEDEN_FUNC_INSTANCE_CALL
std::size_t stos_t(const std::wstring& s)
inline std::size_t wtos_t(const wchar_t* str)
{
if constexpr (sizeof(decltype(std::stoul(s))) == sizeof(std::size_t)) { return static_cast<std::size_t>(std::stoul(s)); }
return static_cast<std::size_t>(std::stoull(s));
static const std::wstring limit = std::to_wstring(std::numeric_limits<std::size_t>::max());
if (str[0] == L'\0' || str[0] == L'-') { throw std::invalid_argument("The string cannot not be converted as an integer."); }
const wchar_t* number = str;
if (str[0] == L'+')
{
if (str[1] == L'\0') { throw std::invalid_argument("The string cannot not be converted as an integer."); }
++number;
}
std::size_t number_size = std::wcslen(str);
const wchar_t* number_end = number;
while (*number_end != L'\0')
{
if (static_cast<std::uint16_t>(*number_end) < 48 || static_cast<std::uint16_t>(*number_end) > 57) { throw std::invalid_argument("The string cannot not be converted as an integer."); }
++number_end;
}
const wchar_t* wchars = limit.c_str();
std::size_t wchars_size = limit.size();
wchar_t* digitsCheck = new wchar_t[wchars_size] { L'\0' };
if (number_size > wchars_size)
{
throw std::out_of_range("An integer is exceeded the limit.");
}
std::int64_t accumulate = 1;
std::int64_t output = 0;
for (std::size_t i = 0; i < number_size; ++i)
{
wchar_t wchar = number[number_size - i - 1];
digitsCheck[number_size - i - 1] = wchar;
std::uint16_t digit = static_cast<std::uint16_t>(wchar) - 48;
output += digit * accumulate;
accumulate = accumulate * 10;
}
if (number_size == wchars_size)
{
for (std::size_t i = 0; i < wchars_size; ++i)
{
if (digitsCheck[i] < wchars[i]) { break; }
else if (digitsCheck[i] > wchars[i]) { throw std::out_of_range("An integer is exceeded the limit."); }
}
}
delete[] digitsCheck;
return output;
};
inline std::size_t stos_t(const std::wstring& str)
{
std::wstring result = std::regex_replace(str, std::wregex(L" "), L"");
return wtos_t(result.c_str());
};
namespace Seden
{
Expand Down

0 comments on commit 361133e

Please sign in to comment.