项目作者: seigtm

项目描述 :
A simple polynomial class that supports all basic operations.
高级语言: C++
项目地址: git://github.com/seigtm/Polynomial.git
创建时间: 2021-04-17T21:36:01Z
项目社区:https://github.com/seigtm/Polynomial

开源协议:

下载


Polynomial C++ template class

In mathematics, a polynomial is an expression consisting of variables (also called indeterminates) and coefficients, that involves only the operations of addition, subtraction, multiplication, and non-negative integer exponentiation of variables.
(https://en.wikipedia.org/wiki/Polynomial)


Constructors:

  1. explicit Polynomial(T value = T(0));
  2. Polynomial(std::initializer_list<T> init);
  3. template<class InputIt>
  4. Polynomial(InputIt first, InputIt last);

List of supported operators and functions:

  • unary;
  • addition;
  • substraction;
  • multiplication;
  • division;
  • comparison (equality);
  • bitwise (for std::cin and std::cout).

Usage examples:

  1. Polynomial<double> minuend{ 8.2, -3.1, 15.1, 0, 2.2 };
  2. // subtrahend = x^3 + 15x^2 + 6.1x + 4.2.
  3. Polynomial<double> subtrahend{ 4.2, 6.1, 15.0, 1 };
  4. // Output: 2.2x^4 - x^3 + 0.1x^2 - 9.2x + 4.
  5. std::cout << minuend - subtrahend;
  1. // multiplier = 5x^4 + 4x^3 + 3x^2 + 2x + 1.
  2. Polynomial<int> multiplier{ 1, 2, 3, 4, 5 };
  3. // Output: 25x^4 + 20x^3 + 15x^2 + 10x + 5.
  4. std::cout << 5 * multiplier;
  1. // first = 8.17x^2 - 15.1x + 3.
  2. std::vector<float> firstData = { 3.0, -15.1, 8.17 };
  3. Polynomial<float> first(firstData.cbegin(), firstData.cend());
  4. // second = 8.17x^2 - 15.1x + 2.
  5. std::vector<float> secondData = { 2.0, -15.1, 8.17 };
  6. Polynomial<float> second{ secondData.cbegin(), secondData.cend() };
  7. // Output: true, as expected.
  8. std::cout << std::boolalpha << (first == (second + 1));

Cloning the repository:

  1. bash> git clone https://github.com/seigtm/Polynomial

Build requirements:

  • cmake to configure the project (minimum required version is 3.5).
  • conan to download all application dependencies.
    You can install conan by giving a command to pip:
    1. bash> pip install --user conan
    To use pip you need to install the python interpreter. I highly recommend to install python3-based versions in order to avoid unexpected results when using conan.

Configuring and build with conan and cmake:

To install with conan, execute the commands:

  1. bash> cd Polynomial
  2. bash> conan install . -if build --build missing

To build and run the project with cmake, execute:

  1. bash> cd build
  2. bash> cmake ..

To install and run the application, execute:

  1. bash> make
  2. bash> cd bin
  3. bash> ./main