Skip to content

Commit

Permalink
Added other inverse functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZCG-coder committed Jun 16, 2024
1 parent 692a7e9 commit 40d362f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ jobs:
#
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, windows-latest, macos-12, macos-13, macos-14]
os: [ubuntu-latest, windows-2019, macos-12, macos-13, macos-14]
build_type: [Release]
c_compiler: [clang, cl]
python_version: ['3.10', '3.11', '3.12']
include:
- os: windows-latest
- os: windows-2019
c_compiler: cl
cpp_compiler: cl
cmake_extra_options: ''
Expand All @@ -54,7 +54,7 @@ jobs:
cpp_compiler: clang++
cmake_extra_options: '-GNinja'
exclude:
- os: windows-latest
- os: windows-2019
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl
Expand Down
66 changes: 65 additions & 1 deletion src/trig/trig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "util.hpp"

#include <functional>
#include <iostream>
#include <string>

using namespace std::literals;
Expand Down Expand Up @@ -380,7 +381,59 @@ namespace steppable::__internals::arithmetic
return result;
}

// std::string acos(const std::string& x, const int decimals, const int mode) {}
std::string acos(const std::string& x, const int decimals, const int mode)
{
std::string circleAngle;
switch (mode)
{
case 1:
circleAngle = "180";
break;
case 2:
circleAngle = "200";
break;
default:
circleAngle = static_cast<std::string>(constants::PI);
}

// pi
// acos(x) = ----- - asin(x)
// 2
return subtract(circleAngle, asin(x, decimals, mode), 0);
}

std::string asec(const std::string& x, const int decimals, const int mode)
{
if (compare(abs(x, 0), "1", 0) != "0")
error("trig::asec"s, "Arc secant is not defined here."s);

// 1
// asec(x) = acos(---)
// x
return acos(divide("1", x, 0, decimals), decimals, mode);
}

std::string acsc(const std::string& x, const int decimals, const int mode)
{
if (compare(abs(x, 0), "1", 0) != "0")
error("trig::acsc"s, "Arc cosecant is not defined here."s);

// 1
// acsc(x) = asin(---)
// x
return asin(divide("1", x, 0, decimals), decimals, mode);
}

std::string acot(const std::string& x, const int decimals, const int mode)
{
if (compare(abs(x, 0), "1", 0) != "0")
error("trig::acot"s, "Arc cotangent is not defined here."s);

// 1
// acot(x) = atan(---)
// x
return atan(divide("1", x, 0, decimals), decimals, mode);
}
} // namespace steppable::__internals::arithmetic

#ifndef NO_MAIN
Expand All @@ -405,28 +458,39 @@ int main(int _argc, const char* _argv[])

std::function<std::string(const std::string& x, const int decimals, const int mode)> function;

// Basic trigonometric functions
if (command == "sin")
function = arithmetic::sin;
else if (command == "cos")
function = arithmetic::cos;
else if (command == "tan")
function = arithmetic::tan;
// Reciprocal trigonometric functions
else if (command == "csc")
function = arithmetic::csc;
else if (command == "sec")
function = arithmetic::sec;
else if (command == "cot")
function = arithmetic::cot;
// Inverse trigonometric functions
else if (command == "atan")
function = arithmetic::atan;
else if (command == "asin")
function = arithmetic::asin;
else if (command == "acos")
function = arithmetic::acos;
else if (command == "asec")
function = arithmetic::asec;
else if (command == "acsc")
function = arithmetic::acsc;
else if (command == "acot")
function = arithmetic::acot;
// Invalid command
else
{
error("trig::main", "Invalid command."s);
return EXIT_FAILURE;
}
std::cout << function(arg, decimals, mode) << '\n';
}
#endif

0 comments on commit 40d362f

Please sign in to comment.