Basic mathematics utils.
#include <iostream>
#include <vector>
#include "libnumerixpp/core/common.hpp"
#include "libnumerixpp/libnumerixpp.hpp"
auto main() -> int {
println("LIBNUMERIXPP");
double const num = 100.0;
std::cout << "Square " << num << ": " << num_sq << '\n';
std::cout << "Square root " << num << ": " << num_sqr << '\n';
std::cout << '\n';
double const a = -2;
double const b = 5;
double const c = 5;
std::vector<double> const roots =
std::cout << "Quadratic Equation: a=" << a << "; b=" << b << "; c=" << c << '\n';
std::cout << "D=" << d << '\n';
std::cout << "Roots:" << '\n';
for (double const root : roots) {
std::cout << root << '\n';
}
std::cout << '\n';
std::cout << "100+10%: " << nump << '\n';
std::cout << '\n';
double const best_pow_val = 100;
std::cout << "0 oldApproximatePower : base 10 exponent 2: " << pow_results[0] << '\n';
std::cout << "1 anotherApproximatePower: base 10 exponent 2: " << pow_results[1] << '\n';
std::cout << "2 binaryPower : base 10 exponent 2: " << pow_results[2]
<< '\n';
std::cout << "3 fastPowerDividing : base 10 exponent 2: " << pow_results[3] << '\n';
std::cout << "4 fastPowerFractional : base 10 exponent 2: " << pow_results[4] << '\n';
for (int i = 0; i < sizeof(pow_results) / sizeof(pow_results[0]); i++) {
double const error = best_pow_val - pow_results[i];
std::cout << "POW Algorithm #" << i << ": error=" << error << '\n';
}
std::cout << '\n';
return 0;
}
void credits()
print credits
Definition: common.cpp:8
Core utils for mathematics.
auto calculate_roots_by_discriminant(double discriminant, double a, double b) -> std::vector< double >
Calculates the roots by discriminant.
Definition: quadratic_equations.cpp:18
auto calculate_discriminant(double a, double b, double c) -> double
Calculates the discriminant.
Definition: quadratic_equations.cpp:12
auto old_approximate_power(double base, double exponent) -> double
Algorithm for fast exponentiation "'Old' approximation".
Definition: core.cpp:10
auto get_square_root(double num) -> double
Gets the square root.
Definition: core.cpp:94
auto intabs(int x) -> int
Getting the modulus of a number without a comparison operation.
Definition: core.cpp:119
auto fast_power_fractional(double base, double exponent) -> double
Algorithm: "Fractional fast power".
Definition: core.cpp:67
auto another_approximate_power(double base, double exponent) -> double
Algorithm for fast exponentiation "'Another' approximation".
Definition: core.cpp:55
auto fast_power_dividing(double base, double exponent) -> double
Algorithm: "Dividing fast power".
Definition: core.cpp:38
auto binary_power(double base, unsigned long long exponent) -> double
Algorithm: Binary exponentiation.
Definition: core.cpp:23
auto square_it_up(double num) -> double
Gets the number square (N^2).
Definition: core.cpp:92
auto add_percent_to_number(double number, double percentage) -> double
Adds a percent to number.
Definition: core.cpp:85
Quadratic utils for mathematics.