This is a C++ library that I wrote. It provides a number of useful utilities, including:
- Mathematical functions (e.g., addition, subtraction, multiplication, division)
- Determining if a number is odd, prime, and more.
- Solving quadratic equations (ax^2 + bx + c = 0) and linear equations (ax + by = c).
- Measuring volume, area, length, angles, and more for various shapes using only their vertex points.
- Providing access to 20+ essential mathematical constants.
To install this library, you can either download the source code and build it yourself, or you can use a pre-built package.
To build the library from source, you will need to have CMake installed. Once you haveCMake installed, you can clone the library repository and run the following command:
To use the library, you will need to include the library header file in your source code:
#include "mathlib-cpp/index.cpp"
Then, you can use the library functions like any other function in your code. For example, to calculate the sum of two numbers, you would use the following code:
int arr[] = {1, 2, 3, 4, 5};
int sum = mlb::add(arr, 5);
For extensive documentation, visit the MathLib-cpp Documentation.
Bainary documentation: https://github.com/MarufHasan24/mathlib-cpp/wiki/Bainary-Mathlib‐cpp
Hexadecimal documentation: https://github.com/MarufHasan24/mathlib-cpp/wiki/Hexadecimal-Mathlib‐cpp
Octal documentation: https://github.com/MarufHasan24/mathlib-cpp/wiki/Octal-Mathlib‐cpp
Complex Number : https://github.com/MarufHasan24/mathlib-cpp/wiki/Complex-Number
Here is a simple example of how to use the library:
#include <iostream>
#include "mathlib-cpp/index.cpp"
int main() {
// Calculate the sum of some numbers
int arr[] = {1, 2, 3, 4, 5};
int sum = mlb::add(arr, 5);
// Print the sum to the console.
std::cout << "The sum is: " << sum << std::endl;
return 0;
}
Here's a taste of the functions provided by MathLib-cpp:
-
int add(int a[], int len);
- Description: Computes the sum of elements in an integer array.
- Usage Example:
add(arr, length)
returns the sum of all elements in the arrayarr
of lengthlength
.
-
int sub(int a[], int len);
- Description: Calculates the result of subtracting all elements in an integer array from the first element.
- Usage Example:
sub(arr, length)
returns the result of subtracting all elements in the arrayarr
from the first element.
-
int mul(int a[], int len);
- Description: Multiplies all elements in an integer array together.
- Usage Example:
mul(arr, length)
returns the product of all elements in the arrayarr
.
-
float div(int a[], int len);
- Description: Computes the result of dividing the first element in an integer array by the product of the rest of the elements.
- Usage Example:
div(arr, length)
returns the result of dividing the first element in the arrayarr
by the product of the rest of the elements.
-
float avg(int a[], int len);
- Description: Calculates the average of elements in an integer array.
- Usage Example:
avg(arr, length)
returns the average value of the elements in the arrayarr
.
-
float logx(int base, int x);
- Description: Computes the logarithm of
x
with the specifiedbase
. - Usage Example:
logx(base, x)
returns the logarithm ofx
with the basebase
.
- Description: Computes the logarithm of
-
float rootx(int base, int x);
- Description: Calculates the
base
-th root ofx
. - Usage Example:
rootx(base, x)
returns thebase
-th root ofx
.
- Description: Calculates the
-
int random(int min, int max);
- Description: Generates a random integer between
min
andmax
. - Usage Example:
random(min, max)
returns a random integer within the specified range.
- Description: Generates a random integer between
-
double limit(int tt, int (*fc)(int));
- Description: Evaluates the limit of a given mathematical function
fc
as the variable approachestt
. - Usage Example:
limit(tt, function)
calculates the limit of the provided function as it approachestt
.
- Description: Evaluates the limit of a given mathematical function
-
double fact(int n);
- Description: Computes the factorial of an integer
n
. - Usage Example:
fact(n)
returns the factorial ofn
.
- Description: Computes the factorial of an integer
-
float* linearEq(float x[], float y[]);
- Description: Solves a system of linear equations with one variable using the provided arrays of
x
andy
values. - Usage Example:
linearEq(x, y)
returns an array containing the solution to the linear equation system. - Note: If the system has no solution, the function returns
NULL
. It will return the pointer to the result array.
- Description: Solves a system of linear equations with one variable using the provided arrays of
-
float* quadEq(float a, float b, float c);
- Description: Solves a quadratic equation with coefficients
a
,b
, andc
. - Usage Example:
quadEq(a, b, c)
returns an array containing the roots of the quadratic equation. - Note: If the equation has no real roots, the function returns
NULL
. It will return the pointer to the result array.
- Description: Solves a quadratic equation with coefficients
-
bool isPrime(int n);
- Description: Checks if an integer
n
is a prime number. - Usage Example:
isPrime(n)
returnstrue
ifn
is prime; otherwise, it returnsfalse
.
- Description: Checks if an integer
-
bool isOdd(int n);
- Description: Determines if an integer
n
is an odd number. - Usage Example:
isOdd(n)
returnstrue
ifn
is odd; otherwise, it returnsfalse
.
- Description: Determines if an integer
-
int sums(int start, int end, int (*fc)(int));
- Description: Calculates the sum of function values from
start
toend
using the provided functionfc
. - Usage Example:
sums(start, end, function)
returns the sum of function values within the specified range.
- Description: Calculates the sum of function values from
-
double combo(int n, int r);
- Description: Computes the number of combinations (n choose r) for given values of
n
andr
. - Usage Example:
combo(n, r)
returns the number of combinations ofn
items takenr
at a time.
- Description: Computes the number of combinations (n choose r) for given values of
-
double permt(int n, int r);
- Description: Calculates the number of permutations for given values of
n
andr
. - Usage Example:
permt(n, r)
returns the number of permutations ofn
items takenr
at a time.
- Description: Calculates the number of permutations for given values of
-
int gcd(int a, int b);
- Description: Finds the greatest common divisor (GCD) of two integers
a
andb
. - Usage Example:
gcd(a, b)
returns the GCD ofa
andb
.
- Description: Finds the greatest common divisor (GCD) of two integers
-
int lcm(int a, int b);
- Description: Calculates the least common multiple (LCM) of two integers
a
andb
. - Usage Example:
lcm(a, b)
returns the LCM ofa
andb
.
- Description: Calculates the least common multiple (LCM) of two integers
-
int* primes(int start, int end);
- Description: Generates an array of prime numbers within the specified range
[start, end]
. - Usage Example:
primes(start, end)
returns an array of prime numbers betweenstart
andend
. - Note: It will return the pointer to the result array.
- Description: Generates an array of prime numbers within the specified range
This library is licensed under the MIT License. You can find the full license text in the LICENSE
file.
If you have questions, bug reports, feature requests, or need general assistance, don't hesitate to reach out at gamerid703@gmail.com, or create an issue on the GitHub repository.