Skip to content

Commit cb004d1

Browse files
authored
version 1.0.0
1 parent fd5d0ce commit cb004d1

3 files changed

Lines changed: 257 additions & 0 deletions

File tree

const.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace mathlib {
2+
long double h= 6.62607004e-34,
3+
G= 6.67428e-11,
4+
g= 9.80665,
5+
mE= 5.97219e24,
6+
gM= 1.634441667,
7+
gMr= 2.4516625,
8+
Na= 6.02214086e23,
9+
c= 299792458,
10+
Phi= 1.6180339887498948482,
11+
W= 2.09455148154232659148,
12+
G1= 0.83462684167407318628,
13+
K= 1.380649e-23,
14+
Me= 9.1093837015e-31,
15+
Mp= 1.67262192369e-27,
16+
Mn= 1.67492749804e-27,
17+
ge= -2.00231930436256,
18+
c12= 1.6605390395999472e-24,
19+
F= 96485.33,
20+
Ce= -1.602176e-19,
21+
Cp= 1.602176e-19,
22+
Ri= 1.0973731568539,
23+
B3= 0.83564884826472105333,
24+
G0= 7.7480917e-5;
25+
};

index.cpp

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
#include <cmath>
2+
#include <bits/stdc++.h>
3+
4+
namespace mathlib {
5+
// Function to add two or more numbers
6+
double add(int a[], int len){
7+
double sum = 0;
8+
for(int i = 0; i < len; i++){
9+
sum += a[i];
10+
}
11+
return sum;
12+
}
13+
// Function to subtract between two or more numbers
14+
double sub(int a[], int len){
15+
double sum = 0;
16+
for(int i = 0; i < len; i++){
17+
sum -= a[i];
18+
}
19+
return sum;
20+
}
21+
// Function to multiply two or more numbers
22+
double mul(int a[], int len){
23+
double sum = 1;
24+
for(int i = 0; i < len; i++){
25+
sum *= a[i];
26+
}
27+
return sum;
28+
}
29+
// Function to divide between two or more numbers
30+
float div(int a[], int len){
31+
float sum = 1;
32+
for(int i = 0; i < len; i++){
33+
sum /= a[i];
34+
}
35+
return sum;
36+
}
37+
// Function to find average of two or more numbers
38+
float avg(int a[], int len){
39+
float sum = 0;
40+
for(int i = 0; i < len; i++){
41+
sum += a[i];
42+
}
43+
return sum/len;
44+
}
45+
// Function to find log of x to for custom base
46+
float logx(int base, int x){
47+
return log(x)/log(base);
48+
}
49+
// Function to find root of x to for custom base
50+
float rootx(int base, int x){
51+
return pow(x, 1.0/base);
52+
}
53+
// Function to generate random number between min and max
54+
int random(int min, int max){
55+
if(min > max){
56+
int temp = min;
57+
min = max;
58+
max = temp;
59+
}
60+
return rand()%(max-min + 1) + min;
61+
}
62+
// Function to find limit of a function
63+
double limit(int tt, double (*fc)(double))
64+
{
65+
int n;
66+
double a = pow(10,-7);
67+
double lim = (fc(tt - a) + fc(tt + a)) / 2;
68+
return lim;
69+
}
70+
// Function to find factorial of a number
71+
double fact(int n){
72+
if(n == 0){
73+
return 1;
74+
}
75+
return n*fact(n-1);
76+
}
77+
/* Function to find 2 linear equations solution from a, b, c of both equations. like ax + by = c */
78+
float* linearEq(float x[], float y[]){
79+
static float result[2];
80+
float a1 = x[0], b1 = x[1], c1 = x[2], a2 = y[0], b2 = y[1], c2 = y[2];
81+
result[0] = (c1 * b2 - c2 * b1) / (a1 * b2 - b1 * a2);
82+
result[1] = (a1 * c2 - a2 * c1) / (a1 * b2 - a2 * b1);
83+
return result;
84+
}
85+
/* Function to find quadratic equation solution from a, b, c of equation. like ax^2 + bx + c = 0 */
86+
float* quadEq(float a, float b, float c){
87+
float d = pow(b, 2) - 4 * a * c;
88+
static float result[2];
89+
if(d > 0){
90+
result[0] = (-b + sqrt(d)) / (2 * a);
91+
result[1] = (-b - sqrt(d)) / (2 * a);
92+
}else if(d == 0){
93+
result[0] = result[1] = -b / (2 * a);
94+
}else{
95+
result[0] = result[1] = nan("");
96+
}
97+
return result;
98+
}
99+
// check if a number is prime or not
100+
bool isPrime(int n){
101+
if(n <= 1){
102+
return false;
103+
}
104+
else {
105+
for(int i = 2; i <= n; i++){
106+
if(n%i == 0){
107+
return false;
108+
}
109+
}
110+
return true;
111+
}
112+
}
113+
// check if a number is odd or not
114+
bool isOdd(int n){
115+
if(n%2 == 0){
116+
return false;
117+
}
118+
return true;
119+
}
120+
// get summation of a series
121+
double sums(int start, int end, double (*fc)(double)){
122+
if(start > end){
123+
int temp = start;
124+
start = end;
125+
end = temp;
126+
}
127+
double sum = 0;
128+
for(int i = start; i <= end; i++){
129+
sum += fc(i);
130+
}
131+
return sum;
132+
}
133+
// get combination of nCr
134+
double combo(int n, int r){
135+
if(n>=0 && r>=0 && n>=r){
136+
return fact(n)/(fact(r)*fact(n-r));
137+
}else{
138+
return nan("");
139+
}
140+
}
141+
// get permutation of nPr
142+
double permt(int n, int r){
143+
if(n>=0 && r>=0 && n>=r){
144+
return fact(n)/fact(n-r);
145+
}else{
146+
return nan("");
147+
}
148+
}
149+
// get gcd of two numbers
150+
int gcd(int a, int b){
151+
if(a == 0){
152+
return b;
153+
}
154+
return gcd(b%a, a);
155+
}
156+
// get lcm of two numbers
157+
int lcm(int a, int b){
158+
return (a*b)/gcd(a, b);
159+
}
160+
// get all prime numbers between two numbers
161+
int* primes(int start, int end){
162+
if(start > end){
163+
int temp = start;
164+
start = end;
165+
end = temp;
166+
}
167+
static int result[100];
168+
int j = 0;
169+
for(int i = start; i <= end; i++){
170+
if(isPrime(i)){
171+
j++;
172+
result[j] = i;
173+
}
174+
}
175+
return result;
176+
}
177+
}

mesure.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <cmath>
2+
#include <bits/stdc++.h>
3+
#define PI 3.141592653589793
4+
namespace mathlib {
5+
// Function to measure length of a line from it's edge points
6+
float lineWidth(int x[], int y[]){
7+
return sqrt(pow(x[1]-x[0], 2) + pow(y[1]-y[0], 2));
8+
}
9+
// Function to measure Perimeter from edge points
10+
float Perimeter(int towD[][2], int len){
11+
float sum = 0;
12+
for(int i = 0; i < len-1; i++){
13+
sum += lineWidth(towD[i], towD[i+1]);
14+
}
15+
sum += lineWidth(towD[len-1], towD[0]);
16+
return sum;
17+
}
18+
// Function to measure area of a rectangle from it's edge points
19+
float Area(int towD[][2], int len){
20+
float sum = 0;
21+
for(int i = 0; i < len-1; i++){
22+
sum += towD[i][0]*towD[i+1][1] - towD[i+1][0]*towD[i][1];
23+
}
24+
sum += towD[len-1][0]*towD[0][1] - towD[0][0]*towD[len-1][1];
25+
return abs(sum/2);
26+
}
27+
// Function to measure volume of a cuboid from it's edge points
28+
float Volume(int threeD[][3], int len){
29+
float sum = 0;
30+
for(int i = 0; i < len-1; i++){
31+
sum += threeD[i][0]*threeD[i+1][1]*threeD[i+2][2] - threeD[i+2][0]*threeD[i+1][1]*threeD[i][2];
32+
}
33+
sum += threeD[len-1][0]*threeD[0][1]*threeD[1][2] - threeD[1][0]*threeD[0][1]*threeD[len-1][2];
34+
return abs(sum/6);
35+
}
36+
// Function to measure surface area of a cuboid from it's edge points
37+
float SurfaceArea(int threeD[][3], int len){
38+
float sum = 0;
39+
for(int i = 0; i < len-1; i++){
40+
sum += lineWidth(threeD[i], threeD[i+1])*lineWidth(threeD[i+1], threeD[i+2]);
41+
}
42+
sum += lineWidth(threeD[len-1], threeD[0])*lineWidth(threeD[0], threeD[1]);
43+
return abs(sum*2);
44+
}
45+
float* tringleAngle(int x[], int y[], int z[]){
46+
float a = lineWidth(x, y);
47+
float b = lineWidth(y, z);
48+
float c = lineWidth(z, x);
49+
static float result[3];
50+
result[0] = acos((pow(b, 2) + pow(c, 2) - pow(a, 2))/(2*b*c));
51+
result[1] = acos((pow(a, 2) + pow(c, 2) - pow(b, 2))/(2*a*c));
52+
result[2] = acos((pow(a, 2) + pow(b, 2) - pow(c, 2))/(2*a*b));
53+
return result;
54+
}
55+
}

0 commit comments

Comments
 (0)