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 Jan 9, 2024
1 parent f26a06f commit 7227849
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
8 changes: 5 additions & 3 deletions C++/Complex Linux.rar/Complex/Complex Testing Console/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ inline double PraseAsReal(const std::wstring& Value)
{
std::wstring Replaced = Replace(Value, L" ", L"");
std::size_t Processed = 0;
double Result = std::stod(Replaced, &Processed);
if (Processed < Replaced.size()) { throw std::invalid_argument("The string cannot be converted as a real."); }
return Result;
double Result = 0;
try { Result = std::stod(Replaced, &Processed); }
catch (...) { Processed = std::wstring::npos; }
if (Processed == Replaced.size()) { return Result; }
throw std::invalid_argument("The string cannot be converted as a real.");
};
namespace ComplexTestingConsole
{
Expand Down
15 changes: 6 additions & 9 deletions C++/Complex Linux.rar/Complex/Complex/Cayley Dickson Algebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ class Factor
{
return right(size >> 1);
};
template <bool Shift>
friend constexpr bool Check(Factor& Union, Factor& Value);
friend constexpr Factor MakeFactor(const Factor& Value);
friend constexpr void AsVector(Factor& Value);
Expand All @@ -370,11 +369,9 @@ class Factor
friend constexpr Factor number_even(const Factor& Union, const Factor& Value);
friend constexpr Factor number_cross(const Factor& Union, const Factor& Value);
};
template <bool Shift>
constexpr bool Check(Factor& Union, Factor& Value)
{
std::size_t Offset = Shift ? 1 : 0;
if (!is_factor(Union.size + Offset) || !is_factor(Value.size + Offset))
if (!is_factor(Union.size) || !is_factor(Value.size))
{
throw std::invalid_argument("The size must be a number which is 2 to the power of a natural number.");
}
Expand Down Expand Up @@ -447,7 +444,7 @@ constexpr Factor operator *(const Factor& Union, const Factor& Value)
{
Factor NumUnion = Union;
Factor NumValue = Value;
if (Check<false>(NumUnion, NumValue)) { return Factor{ GetScalar(NumUnion) * GetScalar(NumValue) }; }
if (Check(NumUnion, NumValue)) { return Factor{ GetScalar(NumUnion) * GetScalar(NumValue) }; }
Factor MergeLeft = NumUnion.left() * NumValue.left() - ~NumValue.right() * NumUnion.right();
Factor MergeRight = NumValue.right() * NumUnion.left() + NumUnion.right() * ~NumValue.left();
return Factor::merge(MergeLeft, MergeRight);
Expand All @@ -471,7 +468,7 @@ constexpr double number_dot(const Factor& Union, const Factor& Value)
{
Factor NumUnion = Union;
Factor NumValue = Value;
Check<false>(NumUnion, NumValue);
Check(NumUnion, NumValue);
return Dot(NumUnion, NumValue);
};
constexpr Factor number_outer(const Factor& Union, const Factor& Value)
Expand All @@ -482,7 +479,7 @@ constexpr Factor number_outer(const Factor& Union, const Factor& Value)
double ScaValue = GetScalar(Value);
Factor VecValue = Value;
AsVector(VecValue);
Check<true>(VecUnion, VecValue);
Check(VecUnion, VecValue);
return number_cross(VecUnion, VecValue) + ScaUnion * VecValue - ScaValue * VecUnion;
};
constexpr Factor number_even(const Factor& Union, const Factor& Value)
Expand All @@ -493,14 +490,14 @@ constexpr Factor number_even(const Factor& Union, const Factor& Value)
double ScaValue = GetScalar(Value);
Factor VecValue = Value;
AsVector(VecValue);
Check<true>(VecUnion, VecValue);
Check(VecUnion, VecValue);
return Factor{ ScaUnion * ScaValue - Dot(VecUnion, VecValue) } + ScaUnion * VecValue + ScaValue * VecUnion;
};
constexpr Factor number_cross(const Factor& Union, const Factor& Value)
{
Factor NumUnion = Union;
Factor NumValue = Value;
Check<false>(NumUnion, NumValue);
Check(NumUnion, NumValue);
AsVector(NumUnion);
AsVector(NumValue);
Factor Result = NumUnion * NumValue;
Expand Down

0 comments on commit 7227849

Please sign in to comment.