Skip to content

Commit 2207478

Browse files
committed
Merge branch 'dev' into main
2 parents 1178d84 + 78be4d1 commit 2207478

File tree

4 files changed

+66
-10
lines changed

4 files changed

+66
-10
lines changed

FunTras/src/funtras.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <funtras.hpp>
2-
2+
#include <math.h>
33

44
// Calcula el factorial de n -> (n)!
55
long double funtras::fact(int n){
@@ -241,6 +241,11 @@ double funtras::atan_t(double x){
241241
}
242242
}
243243

244+
// Aproxima el valor del arcocoseno
245+
double funtras::acos_t(double x){
246+
return funtras::pi_t()*funtras::div_t(2) - funtras::asin_t(x);
247+
}
248+
244249

245250
// Aproxima el valor de la raiz cuadrada
246251
double funtras::sqrt_t(double x){
@@ -267,3 +272,20 @@ double funtras::log_t(double x,double a){
267272
else
268273
return funtras::ln_t(x)*funtras::div_t(funtras::ln_t(a));
269274
}
275+
276+
277+
// Aproxima el valor de PI
278+
double funtras::pi_t(){
279+
double pi = 0;
280+
double error = funtras::tolerancia + 1;
281+
int k = 0, den;
282+
283+
while (error > funtras::tolerancia && k < funtras::max_iteraciones){
284+
den = (2*k)+1;
285+
pi += 4*funtras::power_t(k,-1)* funtras::div_t(den);
286+
error = abs( pi- M_PI );
287+
k++;
288+
}
289+
290+
return pi;
291+
}

FunTras/src/funtras.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ namespace funtras {
112112
/**
113113
* @brief Realiza la aproximacion de arcoseno de una variable.
114114
* @param x Valor de la variable.
115-
* @return El resultado de acos(x).
115+
* @return El resultado de asin(x).
116116
*/
117117
double asin_t(double x);
118118

@@ -123,6 +123,13 @@ namespace funtras {
123123
*/
124124
double atan_t(double x);
125125

126+
/**
127+
* @brief Realiza la aproximacion de arcocoseno de una variable.
128+
* @param x Valor de la variable.
129+
* @return El resultado de acos(x).
130+
*/
131+
double acos_t(double x);
132+
126133
/**
127134
* @brief Realiza la aproximacion de raiz cuadrada de una variable.
128135
* @param x Valor de la variable.
@@ -145,6 +152,13 @@ namespace funtras {
145152
* @return resultado del logaritmo base a, de la variable x.
146153
*/
147154
double log_t(double x, double a);
155+
156+
/**
157+
* @brief Calcula un valor aproximado para PI utilizando la serie de Leibniz.
158+
* @return Valor apróximado de PI.
159+
*/
160+
double pi_t();
161+
148162
};
149163

150164
#endif // H_FUNTRAS

FunTras/test/imp_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ void tan_t_test(){
5555
void asin_t_test(){
5656
cout << funtras::asin_t(0.5) << endl;
5757
cout << funtras::asin_t(-0.3) << endl;
58+
cout << "--- "<< 2*funtras::asin_t(0.9) << endl;
59+
}
60+
61+
void acos_t_test(){
62+
cout << funtras::acos_t(0.5) << endl;
63+
cout << funtras::acos_t(-0.3) << endl;
5864
}
5965

6066
void atan_t_test(){
@@ -76,6 +82,11 @@ void log_t_test(){
7682
cout << funtras::log_t(50,3) << endl;
7783
cout << funtras::log_t(27,7) << endl;
7884
}
85+
86+
void pi_test(){
87+
cout << "PI = "<< funtras::pi_t() << endl;
88+
}
89+
7990
int main(int argc, char const *argv[])
8091
{
8192
power_test();
@@ -93,5 +104,7 @@ int main(int argc, char const *argv[])
93104
sqrt_t_test();
94105
root_t_test();
95106
log_t_test();
107+
pi_test();
108+
acos_t_test();
96109
return 0;
97110
}

install.sh

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,31 @@ fi
1616

1717
cd FunTras
1818

19-
if ! [ -d ./FunTras/build/ ]
20-
then
19+
BUILD=./build
20+
if [ ! -d "$BUILD" ]; then
2121
mkdir build
22-
echo '[OK] Build directory created'
22+
echo '[OK] $BUILD directory created'
2323
else
24-
echo '[OK] /FunTras/build exists on filesystem'
24+
echo '[OK] $BUILD exists on filesystem'
2525
fi
2626

27-
if ! [ -d ./FunTras/lib/ ]
28-
then
27+
LIB=./lib
28+
if [ ! -d "$BUILD" ]; then
2929
mkdir lib
30-
echo '[OK] Lib directory created'
30+
echo '[OK] $LIB directory created'
3131
else
32-
echo '[OK] /FunTras/lib exists on filesystem'
32+
echo '[OK] $LIB exists on filesystem'
3333
fi
3434

3535
# Agregar funtras.hpp
36+
FILE=/usr/include/funtras.hpp
37+
if [ -f "$FILE" ]; then
38+
echo "[OK] $FILE exists"
39+
sudo rm /usr/include/funtras.hpp
40+
fi
41+
3642
sudo cp ./src/funtras.hpp /usr/include
43+
echo "[OK] $FILE stored and updated".
3744

3845
# Compilar y crear biblioteca
3946
g++ -Werror -c ./src/funtras.cpp -o ./build/funtras.o

0 commit comments

Comments
 (0)