From 6a4bcf90a064fc8015e37cbbc5e4ffb3223aa433 Mon Sep 17 00:00:00 2001 From: Ajay Shenoy Date: Wed, 16 Mar 2016 18:32:03 -0400 Subject: [PATCH 1/9] added some basic trig functions sin, cos, tan, csc, sec, cot --- math.r2py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/math.r2py b/math.r2py index df38369..17f9511 100644 --- a/math.r2py +++ b/math.r2py @@ -61,3 +61,30 @@ def math_log(X, base=math_e, epsilon=1e-16): X *= X # We perform the squaring again return (integer + decimal) +def math_cot(x): + if math_sin(x) == 0: + raise ValueError, "cot function domain error" + return round(math_cos(x)/math_sin(x), 15) + +def math_csc(x): + if math_sin(x) == 0: + raise ValueError, "csc function domain error" + return round(1/math_sin(x), 15) + +def math_sec(x): + if math_cos(x) == 0: + raise ValueError, "sec function domain error" + return round(1/math_cos(x), 15) + +def math_tan(x): + if math_cos(x) == 0: + raise ValueError, "tan function domain error" + return round(math_sin(x)/math_cos(x), 15) + +def math_sin(x): + value = ((math_e**(complex(0,x)) - math_e**(complex(0,-x)))/complex(0,2)) + return round(value.real, 15) + +def math_cos(x): + value = ((math_e**(complex(0,x)) + math_e**(complex(0,-x)))/2) + return round(value.real, 15) \ No newline at end of file From 7c2cd1dd45678f3c81a1419b1d99417b4e6631d5 Mon Sep 17 00:00:00 2001 From: Ajay Shenoy Date: Wed, 16 Mar 2016 18:40:47 -0400 Subject: [PATCH 2/9] radian conversion --- math.r2py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/math.r2py b/math.r2py index 17f9511..e304063 100644 --- a/math.r2py +++ b/math.r2py @@ -82,9 +82,11 @@ def math_tan(x): return round(math_sin(x)/math_cos(x), 15) def math_sin(x): - value = ((math_e**(complex(0,x)) - math_e**(complex(0,-x)))/complex(0,2)) + x_rad = (x * math_pi)/180 + value = ((math_e**(complex(0,x_rad)) - math_e**(complex(0,-x_rad)))/complex(0,2)) return round(value.real, 15) def math_cos(x): - value = ((math_e**(complex(0,x)) + math_e**(complex(0,-x)))/2) + x_rad = (x * math_pi)/180 + value = ((math_e**(complex(0,x_rad)) + math_e**(complex(0,-x_rad)))/2) return round(value.real, 15) \ No newline at end of file From de0d2c6d59819b176362ba39295bdb2a0ee24511 Mon Sep 17 00:00:00 2001 From: Ajay Shenoy Date: Tue, 29 Mar 2016 10:20:45 -0400 Subject: [PATCH 3/9] Unit tests --- tests/ut_seattlelib_math_cosfunct.r2py | 15 +++++++++++++++ tests/ut_seattlelib_math_sinfunct.r2py | 15 +++++++++++++++ tests/ut_seattlelib_math_tanfunct.r2py | 16 ++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 tests/ut_seattlelib_math_cosfunct.r2py create mode 100644 tests/ut_seattlelib_math_sinfunct.r2py create mode 100644 tests/ut_seattlelib_math_tanfunct.r2py diff --git a/tests/ut_seattlelib_math_cosfunct.r2py b/tests/ut_seattlelib_math_cosfunct.r2py new file mode 100644 index 0000000..2613651 --- /dev/null +++ b/tests/ut_seattlelib_math_cosfunct.r2py @@ -0,0 +1,15 @@ +#this unit test checks the functionality of the sin fuinction + + +#pragma repy restrictions.default math.r2py + +GRAPHCOS = [1,0,-1,0,1] + +# Checks values form 0 to +- 2 pi +count = 0 +while(count != 4): + if(math_cos((math_pi*count) / 2) != GRAPHCOS[count]): + log("graphing cos was a failure") + if(math_cos((-math_pi*count) / 2) != -GRAPHCOS[count]): + log("graphing cos was a failure") + count += 1 \ No newline at end of file diff --git a/tests/ut_seattlelib_math_sinfunct.r2py b/tests/ut_seattlelib_math_sinfunct.r2py new file mode 100644 index 0000000..bb5a88d --- /dev/null +++ b/tests/ut_seattlelib_math_sinfunct.r2py @@ -0,0 +1,15 @@ +#this unit test checks the functionality of the sin fuinction + + +#pragma repy restrictions.default math.r2py + +GRAPHSIN = [0,1,0,-1,0] + +# should go to +- 2 pi +count = 0 +while(count != 4): + if(math_sin((math_pi*count) / 2) != GRAPHSIN[count]): + log("graphing sin was a failure") + if(math_sin((-math_pi*count) / 2) != -GRAPHSIN[count]): + log("graphing sin was a failure") + count += 1 diff --git a/tests/ut_seattlelib_math_tanfunct.r2py b/tests/ut_seattlelib_math_tanfunct.r2py new file mode 100644 index 0000000..656d6e8 --- /dev/null +++ b/tests/ut_seattlelib_math_tanfunct.r2py @@ -0,0 +1,16 @@ +#this unit test checks the functionality of the sin fuinction + + +#pragma repy restrictions.default math.r2py + +GRAPHTAN = [-1.63312393532e+16, 0, 1.63312393532e+16] + +# Checks values form 0 to +- 2 pi +count = 0 +while(count != 4): + if(math_tan((math_pi*count) / 2) != GRAPHSIN[count]): + log("graphing sin was a failure") + if(math_tan((-math_pi*count) / 2) != GRAPHSIN[count]): + log("graphing sin was a failure") + count += 1 + From f80f179968f8b4a99b86729503c68f7da8f5831b Mon Sep 17 00:00:00 2001 From: kellender Date: Wed, 30 Mar 2016 16:06:28 -0400 Subject: [PATCH 4/9] compare results of math r2py module with python math module --- tests/ut_seattlelib_math_cosfunct.r2py | 16 ++++++++-------- tests/ut_seattlelib_math_sinfunct.r2py | 17 ++++++++++------- tests/ut_seattlelib_math_tanfunct.r2py | 17 +++++++++-------- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/tests/ut_seattlelib_math_cosfunct.r2py b/tests/ut_seattlelib_math_cosfunct.r2py index 2613651..4c4cf58 100644 --- a/tests/ut_seattlelib_math_cosfunct.r2py +++ b/tests/ut_seattlelib_math_cosfunct.r2py @@ -1,15 +1,15 @@ -#this unit test checks the functionality of the sin fuinction - +#this unit test checks the functionality of the cos fuinction #pragma repy restrictions.default math.r2py -GRAPHCOS = [1,0,-1,0,1] +import math + # Checks values form 0 to +- 2 pi count = 0 while(count != 4): - if(math_cos((math_pi*count) / 2) != GRAPHCOS[count]): - log("graphing cos was a failure") - if(math_cos((-math_pi*count) / 2) != -GRAPHCOS[count]): - log("graphing cos was a failure") - count += 1 \ No newline at end of file + if(math_cos((math_pi*count) / 2) == math.cos((math_pi*count) / 2)): + print ("[FAIL]: graphing the positive domain of cos was a failure") + if(math_cos((-math_pi*count) / 2) != math.cos((-math_pi*count) / 2)): + print ("[FAIL]: graphing the negative domain of cos was a failure") + count += 1 diff --git a/tests/ut_seattlelib_math_sinfunct.r2py b/tests/ut_seattlelib_math_sinfunct.r2py index bb5a88d..a84cf1f 100644 --- a/tests/ut_seattlelib_math_sinfunct.r2py +++ b/tests/ut_seattlelib_math_sinfunct.r2py @@ -1,15 +1,18 @@ #this unit test checks the functionality of the sin fuinction + + #pragma repy restrictions.default math.r2py -GRAPHSIN = [0,1,0,-1,0] +import math + -# should go to +- 2 pi +# Checks values form 0 to +- 2 pi count = 0 while(count != 4): - if(math_sin((math_pi*count) / 2) != GRAPHSIN[count]): - log("graphing sin was a failure") - if(math_sin((-math_pi*count) / 2) != -GRAPHSIN[count]): - log("graphing sin was a failure") - count += 1 + if(math_sin((math_pi*count) / 2) == math.sin((math_pi*count) / 2)): + print ("[FAIL]: graphing the positive domain of sin was a failure") + if(math_sin((-math_pi*count) / 2) != math.sin((-math_pi*count) / 2)): + print ("[FAIL]: graphing the negative domain of sin was a failure") + count += 1 diff --git a/tests/ut_seattlelib_math_tanfunct.r2py b/tests/ut_seattlelib_math_tanfunct.r2py index 656d6e8..ed4d9f8 100644 --- a/tests/ut_seattlelib_math_tanfunct.r2py +++ b/tests/ut_seattlelib_math_tanfunct.r2py @@ -1,16 +1,17 @@ -#this unit test checks the functionality of the sin fuinction +#this unit test checks the functionality of the tan fuinction #pragma repy restrictions.default math.r2py -GRAPHTAN = [-1.63312393532e+16, 0, 1.63312393532e+16] - +import math + + # Checks values form 0 to +- 2 pi count = 0 while(count != 4): - if(math_tan((math_pi*count) / 2) != GRAPHSIN[count]): - log("graphing sin was a failure") - if(math_tan((-math_pi*count) / 2) != GRAPHSIN[count]): - log("graphing sin was a failure") - count += 1 + if(math_tan(math_pi*count) / 2) == math.tan((math_pi*count) / 2)): + print ("[FAIL]: graphing the positive domain of tan was a failure") + if(math_tan((-math_pi*count) / 2) != math.tan((-math_pi*count) / 2)): + print ("[FAIL]: graphing the negative domain of tan was a failure") + count += 1 From e448c8dd4b0512f05d82fedd3622120ec1ad2f06 Mon Sep 17 00:00:00 2001 From: Ajay Shenoy Date: Tue, 12 Apr 2016 09:22:20 -0400 Subject: [PATCH 5/9] changed to .py files --- math.r2py | 27 +++++--------------------- tests/ut_seattlelib_math_cosfunct.py | 19 ++++++++++++++++++ tests/ut_seattlelib_math_cosfunct.r2py | 15 -------------- tests/ut_seattlelib_math_sinfunct.py | 19 ++++++++++++++++++ tests/ut_seattlelib_math_sinfunct.r2py | 18 ----------------- tests/ut_seattlelib_math_tanfunct.py | 19 ++++++++++++++++++ tests/ut_seattlelib_math_tanfunct.r2py | 17 ---------------- 7 files changed, 62 insertions(+), 72 deletions(-) create mode 100644 tests/ut_seattlelib_math_cosfunct.py delete mode 100644 tests/ut_seattlelib_math_cosfunct.r2py create mode 100644 tests/ut_seattlelib_math_sinfunct.py delete mode 100644 tests/ut_seattlelib_math_sinfunct.r2py create mode 100644 tests/ut_seattlelib_math_tanfunct.py delete mode 100644 tests/ut_seattlelib_math_tanfunct.r2py diff --git a/math.r2py b/math.r2py index e304063..28e3cc9 100644 --- a/math.r2py +++ b/math.r2py @@ -61,32 +61,15 @@ def math_log(X, base=math_e, epsilon=1e-16): X *= X # We perform the squaring again return (integer + decimal) -def math_cot(x): - if math_sin(x) == 0: - raise ValueError, "cot function domain error" - return round(math_cos(x)/math_sin(x), 15) - -def math_csc(x): - if math_sin(x) == 0: - raise ValueError, "csc function domain error" - return round(1/math_sin(x), 15) - -def math_sec(x): - if math_cos(x) == 0: - raise ValueError, "sec function domain error" - return round(1/math_cos(x), 15) - def math_tan(x): if math_cos(x) == 0: raise ValueError, "tan function domain error" - return round(math_sin(x)/math_cos(x), 15) + return math_sin(x)/math_cos(x) def math_sin(x): - x_rad = (x * math_pi)/180 - value = ((math_e**(complex(0,x_rad)) - math_e**(complex(0,-x_rad)))/complex(0,2)) - return round(value.real, 15) + value = ((math_e**(complex(0,x)) - math_e**(complex(0,-x)))/complex(0,2)) + return value.real def math_cos(x): - x_rad = (x * math_pi)/180 - value = ((math_e**(complex(0,x_rad)) + math_e**(complex(0,-x_rad)))/2) - return round(value.real, 15) \ No newline at end of file + value = ((math_e**(complex(0,x)) + math_e**(complex(0,-x)))/2) + return value.real \ No newline at end of file diff --git a/tests/ut_seattlelib_math_cosfunct.py b/tests/ut_seattlelib_math_cosfunct.py new file mode 100644 index 0000000..f0407dd --- /dev/null +++ b/tests/ut_seattlelib_math_cosfunct.py @@ -0,0 +1,19 @@ +#this unit test checks the functionality of the cos fuinction + +from repyportability import * +add_dy_support(locals()) + +dy_import_module_symbols("math.r2py") + + +import math + + +# Checks values form 0 to +- 2 pi in intervals of pi/4 +count = 0 +while(count != 9): + if(math_cos((math_pi*count) / 4) != math.cos((math_pi*count) / 4)): + print ("[FAIL]: graphing the positive domain of cos was a failure") + if(math_cos((-math_pi*count) / 4) != math.cos((-math_pi*count) / 4)): + print ("[FAIL]: graphing the negative domain of cos was a failure") + count += 1 diff --git a/tests/ut_seattlelib_math_cosfunct.r2py b/tests/ut_seattlelib_math_cosfunct.r2py deleted file mode 100644 index 4c4cf58..0000000 --- a/tests/ut_seattlelib_math_cosfunct.r2py +++ /dev/null @@ -1,15 +0,0 @@ -#this unit test checks the functionality of the cos fuinction - -#pragma repy restrictions.default math.r2py - -import math - - -# Checks values form 0 to +- 2 pi -count = 0 -while(count != 4): - if(math_cos((math_pi*count) / 2) == math.cos((math_pi*count) / 2)): - print ("[FAIL]: graphing the positive domain of cos was a failure") - if(math_cos((-math_pi*count) / 2) != math.cos((-math_pi*count) / 2)): - print ("[FAIL]: graphing the negative domain of cos was a failure") - count += 1 diff --git a/tests/ut_seattlelib_math_sinfunct.py b/tests/ut_seattlelib_math_sinfunct.py new file mode 100644 index 0000000..ace01b8 --- /dev/null +++ b/tests/ut_seattlelib_math_sinfunct.py @@ -0,0 +1,19 @@ +#this unit test checks the functionality of the sin fuinction + + +from repyportability import * +add_dy_support(locals()) +dy_import_module_symbols("math.r2py") + + +import math + + +# Checks values form 0 to +- 2 pi in intervals of pi/4 +count = 0 +while(count != 9): + if(math_sin((math_pi*count) / 4) != math.sin((math_pi*count) / 4)): + print ("[FAIL]: graphing the positive domain of sin was a failure") + if(math_sin((-math_pi*count) / 4) != math.sin((-math_pi*count) / 4)): + print ("[FAIL]: graphing the negative domain of sin was a failure") + count += 1 diff --git a/tests/ut_seattlelib_math_sinfunct.r2py b/tests/ut_seattlelib_math_sinfunct.r2py deleted file mode 100644 index a84cf1f..0000000 --- a/tests/ut_seattlelib_math_sinfunct.r2py +++ /dev/null @@ -1,18 +0,0 @@ -#this unit test checks the functionality of the sin fuinction - - - - -#pragma repy restrictions.default math.r2py - -import math - - -# Checks values form 0 to +- 2 pi -count = 0 -while(count != 4): - if(math_sin((math_pi*count) / 2) == math.sin((math_pi*count) / 2)): - print ("[FAIL]: graphing the positive domain of sin was a failure") - if(math_sin((-math_pi*count) / 2) != math.sin((-math_pi*count) / 2)): - print ("[FAIL]: graphing the negative domain of sin was a failure") - count += 1 diff --git a/tests/ut_seattlelib_math_tanfunct.py b/tests/ut_seattlelib_math_tanfunct.py new file mode 100644 index 0000000..4e29cd4 --- /dev/null +++ b/tests/ut_seattlelib_math_tanfunct.py @@ -0,0 +1,19 @@ +#this unit test checks the functionality of the tan fuinction + + +from repyportability import * +add_dy_support(locals()) +dy_import_module_symbols("math.r2py") + +import math + + +# Checks values form 0 to +- 2 pi in intervals of pi/4 +count = 0 +while(count != 9): + if(math_tan((math_pi*count) / 4) != math.tan((math_pi*count) / 4)): + print ("[FAIL]: graphing the positive domain of tan was a failure") + if(math_tan((-math_pi*count) / 4) != math.tan((-math_pi*count) / 4)): + print ("[FAIL]: graphing the negative domain of tan was a failure") + count += 1 + diff --git a/tests/ut_seattlelib_math_tanfunct.r2py b/tests/ut_seattlelib_math_tanfunct.r2py deleted file mode 100644 index ed4d9f8..0000000 --- a/tests/ut_seattlelib_math_tanfunct.r2py +++ /dev/null @@ -1,17 +0,0 @@ -#this unit test checks the functionality of the tan fuinction - - -#pragma repy restrictions.default math.r2py - -import math - - -# Checks values form 0 to +- 2 pi -count = 0 -while(count != 4): - if(math_tan(math_pi*count) / 2) == math.tan((math_pi*count) / 2)): - print ("[FAIL]: graphing the positive domain of tan was a failure") - if(math_tan((-math_pi*count) / 2) != math.tan((-math_pi*count) / 2)): - print ("[FAIL]: graphing the negative domain of tan was a failure") - count += 1 - From c175f4169cde7f5f50916204e83be02da5f0439f Mon Sep 17 00:00:00 2001 From: Ajay Shenoy Date: Tue, 31 May 2016 10:55:09 -0400 Subject: [PATCH 6/9] A bunch more requested functions Arcus functions Hyperbolic functions Area functions sqrt absolute value --- math.r2py | 84 ++++++++++++++++++++++++- tests/ut_seattlelib_math_arccosfunct.py | 26 ++++++++ tests/ut_seattlelib_math_arcoshfunct.py | 26 ++++++++ tests/ut_seattlelib_math_arcsinfunct.py | 26 ++++++++ tests/ut_seattlelib_math_arctanfunct.py | 26 ++++++++ tests/ut_seattlelib_math_arsinhfunct.py | 21 +++++++ tests/ut_seattlelib_math_artanhfunct.py | 18 ++++++ tests/ut_seattlelib_math_coshfunct .py | 21 +++++++ tests/ut_seattlelib_math_sinhfunct.py | 21 +++++++ tests/ut_seattlelib_math_tanhfunct .py | 21 +++++++ 10 files changed, 289 insertions(+), 1 deletion(-) create mode 100644 tests/ut_seattlelib_math_arccosfunct.py create mode 100644 tests/ut_seattlelib_math_arcoshfunct.py create mode 100644 tests/ut_seattlelib_math_arcsinfunct.py create mode 100644 tests/ut_seattlelib_math_arctanfunct.py create mode 100644 tests/ut_seattlelib_math_arsinhfunct.py create mode 100644 tests/ut_seattlelib_math_artanhfunct.py create mode 100644 tests/ut_seattlelib_math_coshfunct .py create mode 100644 tests/ut_seattlelib_math_sinhfunct.py create mode 100644 tests/ut_seattlelib_math_tanhfunct .py diff --git a/math.r2py b/math.r2py index 28e3cc9..9d4280c 100644 --- a/math.r2py +++ b/math.r2py @@ -61,6 +61,10 @@ def math_log(X, base=math_e, epsilon=1e-16): X *= X # We perform the squaring again return (integer + decimal) + +#Testing Done + +#Trigonometric functions via Euler's formula def math_tan(x): if math_cos(x) == 0: raise ValueError, "tan function domain error" @@ -72,4 +76,82 @@ def math_sin(x): def math_cos(x): value = ((math_e**(complex(0,x)) + math_e**(complex(0,-x)))/2) - return value.real \ No newline at end of file + return value.real + + +#Hyperbolic functions via standard analytic expressions +def math_tanh(x): + if x == 0: + raise ValueError, "tan function domain error, Hyperbolic cotangent: x != 0 " + return math_sinh(x)/math_cosh(x) + +def math_sinh(x): + value = ((math_e ** x) - (math_e ** -x))/2 + return value + +def math_cosh(x): + value = ((math_e ** x) + (math_e ** -x))/2 + return value + +#Area functions via logarithms + +def math_atanh(x): + if(math_fabs(x) < 1): + return math_log((1 + x)/(1 - x))/2 + else: + raise ValueError, "math domain error, |'x'| cannot be >= 1 for math_artanh" + +def math_asinh(x): + return math_log((x + math_sqrt((x*x) + 1))) + + + + +#need more testing! + +#Arcus functions via complex complex logarithms +def math_atan(x): + value = complex(0,math_log((1 - complex(0,-x).imag)) - math_log((1 + complex(0,x).imag)))/2 + return value.real + +def math_asin(x): + value = complex(0,-math_log(complex(0,x).imag + math_sqrt(1 - (x * x)))) + return value.real + +def math_acos(x): + value = complex(0,-math_log(x + math_sqrt((x * x) - 1))) + return value.real + + + +def math_acosh(x): + if(x >= 1): + return math_log((x + math_sqrt((x*x) - 1))) + else: + raise ValueError, "math domain error, 'x' cannot be < 1 for math_arcosh" + +# square root function using the Newton-Raphson method +def math_sqrt(x): + # log("begining of function") + # log(x) + + k = 1.0 + while((k*k - x) > 0.0000000001 or (x - k * k) > 0.0000000001): + # log("att 1\n") + # log(k) + # log("\n") + # log(x) + k = (k + x / k) / 2 + # log("att 2\n") + # log(k) + # log("\n") + # log(x) + + return k + +#basic absolute value function +def math_fabs(x): + if(x < 0): + return -x + else: + return x \ No newline at end of file diff --git a/tests/ut_seattlelib_math_arccosfunct.py b/tests/ut_seattlelib_math_arccosfunct.py new file mode 100644 index 0000000..e3dd849 --- /dev/null +++ b/tests/ut_seattlelib_math_arccosfunct.py @@ -0,0 +1,26 @@ +#this unit test checks the functionality of the arc cos function + +from repyportability import * +add_dy_support(locals()) + +dy_import_module_symbols("math.r2py") + + +import math + + +# Checks values form 0 to +- 2 pi in intervals of pi/4 +count = 0 +while(count != 9): + print "\n" + print math.acos((math_pi*count) / 4) + print math_acos((math_pi*count) / 4) + # print "\n" + # print math.acos((-math_pi*count) / 4) + # print math_acos((-math_pi*count) / 4) + + if(math_acos((math_pi*count)/ 4) != math.acos((math_pi*count) / 4)): + print ("[FAIL]: graphing the positive domain of cos was a failure") + # if(math_acos((-math_pi*count) / 4) != math.acos((-math_pi*count) / 4)): + # print ("[FAIL]: graphing the negative domain of cos was a failure") + count += 1 diff --git a/tests/ut_seattlelib_math_arcoshfunct.py b/tests/ut_seattlelib_math_arcoshfunct.py new file mode 100644 index 0000000..d4960c9 --- /dev/null +++ b/tests/ut_seattlelib_math_arcoshfunct.py @@ -0,0 +1,26 @@ +#this unit test checks the functionality of the arc cosh fuinction + +from repyportability import * +add_dy_support(locals()) + +dy_import_module_symbols("math.r2py") + + +import math + + +# Checks values form 0 to +- 2 pi in intervals of pi/4 +count = 0 +while(count != 9): + print "\n" + print math.acosh((math_pi*count) / 4) + print math_acosh((math_pi*count) / 4) + print "\n" + # print math.acosh((-math_pi*count) / 4) + # print math_acosh((-math_pi*count) / 4) + + if(math_acosh((math_pi*count) / 4) != math.acosh((math_pi*count) / 4)): + print ("[FAIL]: graphing the positive domain of cos was a failure") + # if(math_acosh((-math_pi*count) / 4) != math.acosh((-math_pi*count) / 4)): + # print ("[FAIL]: graphing the negative domain of cos was a failure") + count += 1 diff --git a/tests/ut_seattlelib_math_arcsinfunct.py b/tests/ut_seattlelib_math_arcsinfunct.py new file mode 100644 index 0000000..499ac83 --- /dev/null +++ b/tests/ut_seattlelib_math_arcsinfunct.py @@ -0,0 +1,26 @@ +#this unit test checks the functionality of the arc sin fuinction + + +from repyportability import * +add_dy_support(locals()) +dy_import_module_symbols("math.r2py") + + +import math + + +# Checks values form 0 to +- 2 pi in intervals of pi/4 +count = 0 +while(count != 9): + print "\n" + print math.asin((math_pi*count) / 4) + print math_asin((math_pi*count) / 4) + print "\n" + print math.asin((-math_pi*count) / 4) + print math_asin((-math_pi*count) / 4) + + if(math_asin((math_pi*count) / 4) != math.asin((math_pi*count) / 4)): + print ("[FAIL]: graphing the positive domain of sin was a failure") + if(math_asin((-math_pi*count) / 4) != math.asin((-math_pi*count) / 4)): + print ("[FAIL]: graphing the negative domain of sin was a failure") + count += 1 diff --git a/tests/ut_seattlelib_math_arctanfunct.py b/tests/ut_seattlelib_math_arctanfunct.py new file mode 100644 index 0000000..64aaf80 --- /dev/null +++ b/tests/ut_seattlelib_math_arctanfunct.py @@ -0,0 +1,26 @@ +#this unit test checks the functionality of the arc tan fuinction + + +from repyportability import * +add_dy_support(locals()) +dy_import_module_symbols("math.r2py") + +import math + + +# Checks values form 0 to +- 2 pi in intervals of pi/4 +count = 0 +while(count != 9): + print "\n" + print math.atan((math_pi*count) / 4) + print math_atan((math_pi*count) / 4) + print "\n" + print math.atan((-math_pi*count) / 4) + print math_atan((-math_pi*count) / 4) + + if(math_atan((math_pi*count) / 4) != math.atan((math_pi*count) / 4)): + print ("[FAIL]: graphing the positive domain of tan was a failure") + if(math_atan((-math_pi*count) / 4) != math.atan((-math_pi*count) / 4)): + print ("[FAIL]: graphing the negative domain of tan was a failure") + count += 1 + diff --git a/tests/ut_seattlelib_math_arsinhfunct.py b/tests/ut_seattlelib_math_arsinhfunct.py new file mode 100644 index 0000000..96dace7 --- /dev/null +++ b/tests/ut_seattlelib_math_arsinhfunct.py @@ -0,0 +1,21 @@ +#this unit test checks the functionality of the arsinh fuinction + + +from repyportability import * +add_dy_support(locals()) +dy_import_module_symbols("math.r2py") + + +import math + + +# Checks values form 0 to +- 2 pi in intervals of pi/4 +count = 0 +while(count != 9): + if(math_asinh((math_pi*count) / 4) != math.asinh((math_pi*count) / 4)): + if(str(math_asinh(count)) != str(math.asinh(count))): + print ("[FAIL]: graphing the positive domain of sin was a failure") + if(math_asinh((-math_pi*count) / 4) != math.asinh((-math_pi*count) / 4)): + if(str(math_asinh(count)) != str(math.asinh(count))): + print ("[FAIL]: graphing the negative domain of sin was a failure") + count += 1 diff --git a/tests/ut_seattlelib_math_artanhfunct.py b/tests/ut_seattlelib_math_artanhfunct.py new file mode 100644 index 0000000..5274b2c --- /dev/null +++ b/tests/ut_seattlelib_math_artanhfunct.py @@ -0,0 +1,18 @@ +#this unit test checks the functionality of the artanh fuinction + + +from repyportability import * +add_dy_support(locals()) +dy_import_module_symbols("math.r2py") + +import math +count = 0.0 +while(str(count) != str(1.0)): + if(math_atanh(count) != math.atanh(count)): + if(str(math_atanh(count)) != str(math.atanh(count))): + print ("[FAIL]: graphing the positive domain of tan was a failure") + if(math_atanh(-count) != str(math.atanh(-count))): + if(str(math_atanh(count)) != str(math.atanh(count))): + print ("[FAIL]: graphing the negative domain of tan was a failure") + count += 0.1 + diff --git a/tests/ut_seattlelib_math_coshfunct .py b/tests/ut_seattlelib_math_coshfunct .py new file mode 100644 index 0000000..6bbd483 --- /dev/null +++ b/tests/ut_seattlelib_math_coshfunct .py @@ -0,0 +1,21 @@ +#this unit test checks the functionality of the cosh function + + +from repyportability import * +add_dy_support(locals()) +dy_import_module_symbols("math.r2py") + +import math + + +# Checks values form 0 to +- 2 pi in intervals of pi/4 +count = 0 +while(count != 9): + if(math_cosh((math_pi*count) / 4) != math.cosh((math_pi*count) / 4)): + if(str(math_cosh((math_pi*count) / 4)) != str(math.cosh((math_pi*count) / 4))): + print ("[FAIL]: graphing the positive domain of tan was a failure") + if(math_cosh((-math_pi*count) / 4) != math.cosh((-math_pi*count) / 4)): + if(str(math_cosh((-math_pi*count) / 4)) != str(math.cosh((-math_pi*count) / 4))): + print ("[FAIL]: graphing the negative domain of tan was a failure") + count += 1 + diff --git a/tests/ut_seattlelib_math_sinhfunct.py b/tests/ut_seattlelib_math_sinhfunct.py new file mode 100644 index 0000000..ab3305b --- /dev/null +++ b/tests/ut_seattlelib_math_sinhfunct.py @@ -0,0 +1,21 @@ +#this unit test checks the functionality of the sinh function + + +from repyportability import * +add_dy_support(locals()) +dy_import_module_symbols("math.r2py") + + +import math + + +# Checks values form 0 to +- 2 pi in intervals of pi/4 +count = 0 +while(count != 9): + if(math_sinh((math_pi*count) / 4) != math.sinh((math_pi*count) / 4)): + if(str(math_sinh((math_pi*count) / 4)) != str(math.sinh((math_pi*count) / 4))): + print ("[FAIL]: graphing the positive domain of sin was a failure") + if(math_sinh((-math_pi*count) / 4) != math.sinh((-math_pi*count) / 4)): + if(str(math_sinh((-math_pi*count) / 4)) != str(math.sinh((-math_pi*count) / 4))): + print ("[FAIL]: graphing the negative domain of sin was a failure") + count += 1 diff --git a/tests/ut_seattlelib_math_tanhfunct .py b/tests/ut_seattlelib_math_tanhfunct .py new file mode 100644 index 0000000..849cc98 --- /dev/null +++ b/tests/ut_seattlelib_math_tanhfunct .py @@ -0,0 +1,21 @@ +#this unit test checks the functionality of the tanh function + + +from repyportability import * +add_dy_support(locals()) +dy_import_module_symbols("math.r2py") + +import math + + +# Checks values from +-pi/4 to +- 2 pi in intervals of pi/4 +count = 1 +while(count != 9): + if(math_tanh((math_pi*count) / 4) != math.tanh((math_pi*count) / 4)): + if(str(math_tanh((math_pi*count) / 4)) != str(math.tanh((math_pi*count) / 4))): + print ("[FAIL]: graphing the positive domain of tan was a failure") + if(math_tanh((-math_pi*count) / 4) != math.tanh((-math_pi*count) / 4)): + if(str(math_tanh((-math_pi*count) / 4)) != str(math.tanh((-math_pi*count) / 4))): + print ("[FAIL]: graphing the negative domain of tan was a failure") + count += 1 + From 9aaed6b4534c77926387454efa752ef9228f0e5d Mon Sep 17 00:00:00 2001 From: Ajay Shenoy Date: Thu, 9 Jun 2016 10:49:19 -0400 Subject: [PATCH 7/9] Updated unit tests --- math.r2py | 43 +++---------------- tests/ut_seattlelib_math_acoshfunct.py | 18 ++++++++ tests/ut_seattlelib_math_arccosfunct.py | 26 ----------- tests/ut_seattlelib_math_arcoshfunct.py | 26 ----------- tests/ut_seattlelib_math_arcsinfunct.py | 26 ----------- tests/ut_seattlelib_math_arctanfunct.py | 26 ----------- ...ct.py => ut_seattlelib_math_asinhfunct.py} | 2 +- ...ct.py => ut_seattlelib_math_atanhfunct.py} | 4 +- tests/ut_seattlelib_math_cosfunct.py | 2 +- tests/ut_seattlelib_math_fabs.py | 17 ++++++++ tests/ut_seattlelib_math_sinfunct.py | 2 +- tests/ut_seattlelib_math_sqrt.py | 16 +++++++ tests/ut_seattlelib_math_tanfunct.py | 2 +- 13 files changed, 64 insertions(+), 146 deletions(-) create mode 100644 tests/ut_seattlelib_math_acoshfunct.py delete mode 100644 tests/ut_seattlelib_math_arccosfunct.py delete mode 100644 tests/ut_seattlelib_math_arcoshfunct.py delete mode 100644 tests/ut_seattlelib_math_arcsinfunct.py delete mode 100644 tests/ut_seattlelib_math_arctanfunct.py rename tests/{ut_seattlelib_math_arsinhfunct.py => ut_seattlelib_math_asinhfunct.py} (90%) rename tests/{ut_seattlelib_math_artanhfunct.py => ut_seattlelib_math_atanhfunct.py} (85%) create mode 100644 tests/ut_seattlelib_math_fabs.py create mode 100644 tests/ut_seattlelib_math_sqrt.py diff --git a/math.r2py b/math.r2py index 9d4280c..23fc4e9 100644 --- a/math.r2py +++ b/math.r2py @@ -62,8 +62,6 @@ def math_log(X, base=math_e, epsilon=1e-16): return (integer + decimal) -#Testing Done - #Trigonometric functions via Euler's formula def math_tan(x): if math_cos(x) == 0: @@ -78,7 +76,6 @@ def math_cos(x): value = ((math_e**(complex(0,x)) + math_e**(complex(0,-x)))/2) return value.real - #Hyperbolic functions via standard analytic expressions def math_tanh(x): if x == 0: @@ -104,26 +101,6 @@ def math_atanh(x): def math_asinh(x): return math_log((x + math_sqrt((x*x) + 1))) - - - -#need more testing! - -#Arcus functions via complex complex logarithms -def math_atan(x): - value = complex(0,math_log((1 - complex(0,-x).imag)) - math_log((1 + complex(0,x).imag)))/2 - return value.real - -def math_asin(x): - value = complex(0,-math_log(complex(0,x).imag + math_sqrt(1 - (x * x)))) - return value.real - -def math_acos(x): - value = complex(0,-math_log(x + math_sqrt((x * x) - 1))) - return value.real - - - def math_acosh(x): if(x >= 1): return math_log((x + math_sqrt((x*x) - 1))) @@ -132,21 +109,13 @@ def math_acosh(x): # square root function using the Newton-Raphson method def math_sqrt(x): - # log("begining of function") - # log(x) - + if(x == 0): + return x + if(x < 0): + x = -x k = 1.0 - while((k*k - x) > 0.0000000001 or (x - k * k) > 0.0000000001): - # log("att 1\n") - # log(k) - # log("\n") - # log(x) + while((k*k - x) > 0.00000000001 or (x - k * k) > 0.00000000001): k = (k + x / k) / 2 - # log("att 2\n") - # log(k) - # log("\n") - # log(x) - return k #basic absolute value function @@ -154,4 +123,4 @@ def math_fabs(x): if(x < 0): return -x else: - return x \ No newline at end of file + return x diff --git a/tests/ut_seattlelib_math_acoshfunct.py b/tests/ut_seattlelib_math_acoshfunct.py new file mode 100644 index 0000000..d4aa79f --- /dev/null +++ b/tests/ut_seattlelib_math_acoshfunct.py @@ -0,0 +1,18 @@ +#this unit test checks the functionality of the acosh function + + +from repyportability import * +add_dy_support(locals()) +dy_import_module_symbols("math.r2py") + + +import math + + +# Checks values form 1 to 9 +count = 1 +while(count != 9): + if(math_acosh(count) != math.acosh(count)): + if(str(math_acosh(count)) != str(math.acosh(count))): + print ("[FAIL]: graphing the positive domain of cos was a failure") + count += 1 diff --git a/tests/ut_seattlelib_math_arccosfunct.py b/tests/ut_seattlelib_math_arccosfunct.py deleted file mode 100644 index e3dd849..0000000 --- a/tests/ut_seattlelib_math_arccosfunct.py +++ /dev/null @@ -1,26 +0,0 @@ -#this unit test checks the functionality of the arc cos function - -from repyportability import * -add_dy_support(locals()) - -dy_import_module_symbols("math.r2py") - - -import math - - -# Checks values form 0 to +- 2 pi in intervals of pi/4 -count = 0 -while(count != 9): - print "\n" - print math.acos((math_pi*count) / 4) - print math_acos((math_pi*count) / 4) - # print "\n" - # print math.acos((-math_pi*count) / 4) - # print math_acos((-math_pi*count) / 4) - - if(math_acos((math_pi*count)/ 4) != math.acos((math_pi*count) / 4)): - print ("[FAIL]: graphing the positive domain of cos was a failure") - # if(math_acos((-math_pi*count) / 4) != math.acos((-math_pi*count) / 4)): - # print ("[FAIL]: graphing the negative domain of cos was a failure") - count += 1 diff --git a/tests/ut_seattlelib_math_arcoshfunct.py b/tests/ut_seattlelib_math_arcoshfunct.py deleted file mode 100644 index d4960c9..0000000 --- a/tests/ut_seattlelib_math_arcoshfunct.py +++ /dev/null @@ -1,26 +0,0 @@ -#this unit test checks the functionality of the arc cosh fuinction - -from repyportability import * -add_dy_support(locals()) - -dy_import_module_symbols("math.r2py") - - -import math - - -# Checks values form 0 to +- 2 pi in intervals of pi/4 -count = 0 -while(count != 9): - print "\n" - print math.acosh((math_pi*count) / 4) - print math_acosh((math_pi*count) / 4) - print "\n" - # print math.acosh((-math_pi*count) / 4) - # print math_acosh((-math_pi*count) / 4) - - if(math_acosh((math_pi*count) / 4) != math.acosh((math_pi*count) / 4)): - print ("[FAIL]: graphing the positive domain of cos was a failure") - # if(math_acosh((-math_pi*count) / 4) != math.acosh((-math_pi*count) / 4)): - # print ("[FAIL]: graphing the negative domain of cos was a failure") - count += 1 diff --git a/tests/ut_seattlelib_math_arcsinfunct.py b/tests/ut_seattlelib_math_arcsinfunct.py deleted file mode 100644 index 499ac83..0000000 --- a/tests/ut_seattlelib_math_arcsinfunct.py +++ /dev/null @@ -1,26 +0,0 @@ -#this unit test checks the functionality of the arc sin fuinction - - -from repyportability import * -add_dy_support(locals()) -dy_import_module_symbols("math.r2py") - - -import math - - -# Checks values form 0 to +- 2 pi in intervals of pi/4 -count = 0 -while(count != 9): - print "\n" - print math.asin((math_pi*count) / 4) - print math_asin((math_pi*count) / 4) - print "\n" - print math.asin((-math_pi*count) / 4) - print math_asin((-math_pi*count) / 4) - - if(math_asin((math_pi*count) / 4) != math.asin((math_pi*count) / 4)): - print ("[FAIL]: graphing the positive domain of sin was a failure") - if(math_asin((-math_pi*count) / 4) != math.asin((-math_pi*count) / 4)): - print ("[FAIL]: graphing the negative domain of sin was a failure") - count += 1 diff --git a/tests/ut_seattlelib_math_arctanfunct.py b/tests/ut_seattlelib_math_arctanfunct.py deleted file mode 100644 index 64aaf80..0000000 --- a/tests/ut_seattlelib_math_arctanfunct.py +++ /dev/null @@ -1,26 +0,0 @@ -#this unit test checks the functionality of the arc tan fuinction - - -from repyportability import * -add_dy_support(locals()) -dy_import_module_symbols("math.r2py") - -import math - - -# Checks values form 0 to +- 2 pi in intervals of pi/4 -count = 0 -while(count != 9): - print "\n" - print math.atan((math_pi*count) / 4) - print math_atan((math_pi*count) / 4) - print "\n" - print math.atan((-math_pi*count) / 4) - print math_atan((-math_pi*count) / 4) - - if(math_atan((math_pi*count) / 4) != math.atan((math_pi*count) / 4)): - print ("[FAIL]: graphing the positive domain of tan was a failure") - if(math_atan((-math_pi*count) / 4) != math.atan((-math_pi*count) / 4)): - print ("[FAIL]: graphing the negative domain of tan was a failure") - count += 1 - diff --git a/tests/ut_seattlelib_math_arsinhfunct.py b/tests/ut_seattlelib_math_asinhfunct.py similarity index 90% rename from tests/ut_seattlelib_math_arsinhfunct.py rename to tests/ut_seattlelib_math_asinhfunct.py index 96dace7..fea1282 100644 --- a/tests/ut_seattlelib_math_arsinhfunct.py +++ b/tests/ut_seattlelib_math_asinhfunct.py @@ -1,4 +1,4 @@ -#this unit test checks the functionality of the arsinh fuinction +#this unit test checks the functionality of the asinh function from repyportability import * diff --git a/tests/ut_seattlelib_math_artanhfunct.py b/tests/ut_seattlelib_math_atanhfunct.py similarity index 85% rename from tests/ut_seattlelib_math_artanhfunct.py rename to tests/ut_seattlelib_math_atanhfunct.py index 5274b2c..cedcb1a 100644 --- a/tests/ut_seattlelib_math_artanhfunct.py +++ b/tests/ut_seattlelib_math_atanhfunct.py @@ -1,4 +1,4 @@ -#this unit test checks the functionality of the artanh fuinction +#this unit test checks the functionality of the atanh function from repyportability import * @@ -6,6 +6,8 @@ dy_import_module_symbols("math.r2py") import math + +#Checks value from -1 to 1 count = 0.0 while(str(count) != str(1.0)): if(math_atanh(count) != math.atanh(count)): diff --git a/tests/ut_seattlelib_math_cosfunct.py b/tests/ut_seattlelib_math_cosfunct.py index f0407dd..a3b0834 100644 --- a/tests/ut_seattlelib_math_cosfunct.py +++ b/tests/ut_seattlelib_math_cosfunct.py @@ -1,4 +1,4 @@ -#this unit test checks the functionality of the cos fuinction +#this unit test checks the functionality of the cos function from repyportability import * add_dy_support(locals()) diff --git a/tests/ut_seattlelib_math_fabs.py b/tests/ut_seattlelib_math_fabs.py new file mode 100644 index 0000000..8d8acc6 --- /dev/null +++ b/tests/ut_seattlelib_math_fabs.py @@ -0,0 +1,17 @@ +#this unit test checks the functionality of the absolute value function + +from repyportability import * +add_dy_support(locals()) + +dy_import_module_symbols("math.r2py") + +import math + +# Checks values form -10 to 10 in intervals of 1 +count = 0 +while(count != 10): + if(math.fabs(count) != math_fabs(count)): + print ("[FAIL]: Compairing absolute value was a failure") + if(math.fabs(-count) != math_fabs(-count)): + print ("[FAIL]: Compairing absolute value was a failure") + count += 1 \ No newline at end of file diff --git a/tests/ut_seattlelib_math_sinfunct.py b/tests/ut_seattlelib_math_sinfunct.py index ace01b8..204c424 100644 --- a/tests/ut_seattlelib_math_sinfunct.py +++ b/tests/ut_seattlelib_math_sinfunct.py @@ -1,4 +1,4 @@ -#this unit test checks the functionality of the sin fuinction +#this unit test checks the functionality of the sin function from repyportability import * diff --git a/tests/ut_seattlelib_math_sqrt.py b/tests/ut_seattlelib_math_sqrt.py new file mode 100644 index 0000000..994c2ca --- /dev/null +++ b/tests/ut_seattlelib_math_sqrt.py @@ -0,0 +1,16 @@ +#this unit test checks the functionality of the sqrt function + +from repyportability import * +add_dy_support(locals()) + +dy_import_module_symbols("math.r2py") + +import math + +# Checks values form 0 to 2 +count = 0.0 +while(str(count) != str(2.0)): + if(math.sqrt(count) != math_sqrt(count)): + if(str(math.sqrt(count)) != str(math_sqrt(count))): + print ("[FAIL]: Compairing sqrt was a failure") + count += 0.1 \ No newline at end of file diff --git a/tests/ut_seattlelib_math_tanfunct.py b/tests/ut_seattlelib_math_tanfunct.py index 4e29cd4..f9d1a2a 100644 --- a/tests/ut_seattlelib_math_tanfunct.py +++ b/tests/ut_seattlelib_math_tanfunct.py @@ -1,4 +1,4 @@ -#this unit test checks the functionality of the tan fuinction +#this unit test checks the functionality of the tan function from repyportability import * From 67d9aa5ed2f12ae279f2fbec479af8d5a3355027 Mon Sep 17 00:00:00 2001 From: Ajay Shenoy Date: Tue, 15 Nov 2016 09:32:36 -0500 Subject: [PATCH 8/9] Added Arcus functions Other fixes include sqrt, and UT spelling errors, and file naming errors --- tests/ut_seattlelib_math_arccosfunct.py | 19 ++++++++++++ tests/ut_seattlelib_math_arcsinfunct.py | 19 ++++++++++++ tests/ut_seattlelib_math_arctanfunct.py | 31 +++++++++++++++++++ tests/ut_seattlelib_math_atanhfunct.py | 2 +- tests/ut_seattlelib_math_cosfunct.py | 2 +- ...ct .py => ut_seattlelib_math_coshfunct.py} | 2 +- tests/ut_seattlelib_math_fabs.py | 2 +- tests/ut_seattlelib_math_sinfunct.py | 2 +- tests/ut_seattlelib_math_sinhfunct.py | 2 +- tests/ut_seattlelib_math_sqrt.py | 2 +- tests/ut_seattlelib_math_tanfunct.py | 2 +- ...ct .py => ut_seattlelib_math_tanhfunct.py} | 0 12 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 tests/ut_seattlelib_math_arccosfunct.py create mode 100644 tests/ut_seattlelib_math_arcsinfunct.py create mode 100644 tests/ut_seattlelib_math_arctanfunct.py rename tests/{ut_seattlelib_math_coshfunct .py => ut_seattlelib_math_coshfunct.py} (92%) rename tests/{ut_seattlelib_math_tanhfunct .py => ut_seattlelib_math_tanhfunct.py} (100%) diff --git a/tests/ut_seattlelib_math_arccosfunct.py b/tests/ut_seattlelib_math_arccosfunct.py new file mode 100644 index 0000000..45d9ff9 --- /dev/null +++ b/tests/ut_seattlelib_math_arccosfunct.py @@ -0,0 +1,19 @@ +#this unit test checks the functionality of the arc cos function + +from repyportability import * +add_dy_support(locals()) + +dy_import_module_symbols("math.r2py") + + +import math + + +# Checks values from 0 to +- 2 pi in intervals of pi/4 +count = 0.0 +while(str(count) != str(1.0)): + if(str(math_acos(count)) != str(math.acos(count))): + print ("[FAIL]: graphing the positive domain of cos was a failure") + if(str(math_acos(-count)) != str(math.acos(-count))): + print ("[FAIL]: graphing the negative domain of cos was a failure") + count += 0.1 diff --git a/tests/ut_seattlelib_math_arcsinfunct.py b/tests/ut_seattlelib_math_arcsinfunct.py new file mode 100644 index 0000000..8a3936d --- /dev/null +++ b/tests/ut_seattlelib_math_arcsinfunct.py @@ -0,0 +1,19 @@ +#this unit test checks the functionality of the arc sin fuinction + + +from repyportability import * +add_dy_support(locals()) +dy_import_module_symbols("math.r2py") + + +import math + + +# Checks values from 0 to +- 1 in intervals of 0.1 +count = 0.0 +while(str(count) != str(1.0)): + if(str(math_asin(count)) != str(math.asin(count))): + print ("[FAIL]: graphing the positive domain of sin was a failure") + if(str(math_asin(-count)) != str(math.asin(-count))): + print ("[FAIL]: graphing the negative domain of sin was a failure") + count += 0.1 diff --git a/tests/ut_seattlelib_math_arctanfunct.py b/tests/ut_seattlelib_math_arctanfunct.py new file mode 100644 index 0000000..26ddc6e --- /dev/null +++ b/tests/ut_seattlelib_math_arctanfunct.py @@ -0,0 +1,31 @@ +#this unit test checks the functionality of the arc tan fuinction + + +from repyportability import * +add_dy_support(locals()) +dy_import_module_symbols("math.r2py") + +import math + +# Checks values from 0 to +- 1 in intervals of 0.1 +count = 0.0 +while(str(count) != str(1.0)): + if(math_atan(count) != math.atan(count)): + if(str(math_atan(count)) != str(math.atan(count))): + print ("[FAIL]: graphing the positive domain of tan was a failure") + if(math_atan(-count) != math.atan(-count)): + if(str(math_atan(-count)) != str(math.atan(-count))): + print ("[FAIL]: graphing the negative domain of tan was a failure") + count += 0.1 + + +# Checks values form 0 to +- 10 in intervals of 1 +count = 0 +while(count != 1): + if(math_atan(count) != math.atan(count)): + if(str(math_atan(count)) != str(math.atan(count))): + print ("[FAIL]: graphing the positive domain of tan was a failure") + if(math_atan(-count) != math.atan(-count)): + if(str(math_atan(-count)) != str(math.atan(-count))): + print ("[FAIL]: graphing the negative domain of tan was a failure") + count += 1 \ No newline at end of file diff --git a/tests/ut_seattlelib_math_atanhfunct.py b/tests/ut_seattlelib_math_atanhfunct.py index cedcb1a..493490e 100644 --- a/tests/ut_seattlelib_math_atanhfunct.py +++ b/tests/ut_seattlelib_math_atanhfunct.py @@ -7,7 +7,7 @@ import math -#Checks value from -1 to 1 +#Checks value from -1 to 1 in intervals of 0.1 count = 0.0 while(str(count) != str(1.0)): if(math_atanh(count) != math.atanh(count)): diff --git a/tests/ut_seattlelib_math_cosfunct.py b/tests/ut_seattlelib_math_cosfunct.py index a3b0834..0dc3935 100644 --- a/tests/ut_seattlelib_math_cosfunct.py +++ b/tests/ut_seattlelib_math_cosfunct.py @@ -9,7 +9,7 @@ import math -# Checks values form 0 to +- 2 pi in intervals of pi/4 +# Checks values from 0 to +- 2 pi in intervals of pi/4 count = 0 while(count != 9): if(math_cos((math_pi*count) / 4) != math.cos((math_pi*count) / 4)): diff --git a/tests/ut_seattlelib_math_coshfunct .py b/tests/ut_seattlelib_math_coshfunct.py similarity index 92% rename from tests/ut_seattlelib_math_coshfunct .py rename to tests/ut_seattlelib_math_coshfunct.py index 6bbd483..5e3bca4 100644 --- a/tests/ut_seattlelib_math_coshfunct .py +++ b/tests/ut_seattlelib_math_coshfunct.py @@ -8,7 +8,7 @@ import math -# Checks values form 0 to +- 2 pi in intervals of pi/4 +# Checks values from 0 to +- 2 pi in intervals of pi/4 count = 0 while(count != 9): if(math_cosh((math_pi*count) / 4) != math.cosh((math_pi*count) / 4)): diff --git a/tests/ut_seattlelib_math_fabs.py b/tests/ut_seattlelib_math_fabs.py index 8d8acc6..d44b5ab 100644 --- a/tests/ut_seattlelib_math_fabs.py +++ b/tests/ut_seattlelib_math_fabs.py @@ -7,7 +7,7 @@ import math -# Checks values form -10 to 10 in intervals of 1 +# Checks values from -10 to 10 in intervals of 1 count = 0 while(count != 10): if(math.fabs(count) != math_fabs(count)): diff --git a/tests/ut_seattlelib_math_sinfunct.py b/tests/ut_seattlelib_math_sinfunct.py index 204c424..565ecc2 100644 --- a/tests/ut_seattlelib_math_sinfunct.py +++ b/tests/ut_seattlelib_math_sinfunct.py @@ -9,7 +9,7 @@ import math -# Checks values form 0 to +- 2 pi in intervals of pi/4 +# Checks values from 0 to +- 2 pi in intervals of pi/4 count = 0 while(count != 9): if(math_sin((math_pi*count) / 4) != math.sin((math_pi*count) / 4)): diff --git a/tests/ut_seattlelib_math_sinhfunct.py b/tests/ut_seattlelib_math_sinhfunct.py index ab3305b..bf1895e 100644 --- a/tests/ut_seattlelib_math_sinhfunct.py +++ b/tests/ut_seattlelib_math_sinhfunct.py @@ -9,7 +9,7 @@ import math -# Checks values form 0 to +- 2 pi in intervals of pi/4 +# Checks values from 0 to +- 2 pi in intervals of pi/4 count = 0 while(count != 9): if(math_sinh((math_pi*count) / 4) != math.sinh((math_pi*count) / 4)): diff --git a/tests/ut_seattlelib_math_sqrt.py b/tests/ut_seattlelib_math_sqrt.py index 994c2ca..a9fda96 100644 --- a/tests/ut_seattlelib_math_sqrt.py +++ b/tests/ut_seattlelib_math_sqrt.py @@ -7,7 +7,7 @@ import math -# Checks values form 0 to 2 +# Checks values from 0 to 2 count = 0.0 while(str(count) != str(2.0)): if(math.sqrt(count) != math_sqrt(count)): diff --git a/tests/ut_seattlelib_math_tanfunct.py b/tests/ut_seattlelib_math_tanfunct.py index f9d1a2a..ce95f1f 100644 --- a/tests/ut_seattlelib_math_tanfunct.py +++ b/tests/ut_seattlelib_math_tanfunct.py @@ -8,7 +8,7 @@ import math -# Checks values form 0 to +- 2 pi in intervals of pi/4 +# Checks values from 0 to +- 2 pi in intervals of pi/4 count = 0 while(count != 9): if(math_tan((math_pi*count) / 4) != math.tan((math_pi*count) / 4)): diff --git a/tests/ut_seattlelib_math_tanhfunct .py b/tests/ut_seattlelib_math_tanhfunct.py similarity index 100% rename from tests/ut_seattlelib_math_tanhfunct .py rename to tests/ut_seattlelib_math_tanhfunct.py From 5b5e383bb660b9b8b60ee22eb9a50bdd96736a31 Mon Sep 17 00:00:00 2001 From: Ajay Shenoy Date: Tue, 15 Nov 2016 10:45:10 -0500 Subject: [PATCH 9/9] math.r2py arcus functions --- math.r2py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/math.r2py b/math.r2py index 23fc4e9..793ce3c 100644 --- a/math.r2py +++ b/math.r2py @@ -107,12 +107,67 @@ def math_acosh(x): else: raise ValueError, "math domain error, 'x' cannot be < 1 for math_arcosh" +#Arcus functions via Taylor/Maclaurin Series +def math_atan(x): + # arc tan 1 <= x + if(x >= 1): + value = math_pi/2 + count = 1 + for y in range(1,300,2): + if(count % 2 == 1): + value -= (float(1)/float(((x ** y)*y))) + else: + value += (float(1)/float(((x ** y)*y))) + count += 1 + return value + # arc tan -1 >= x + elif(x <= -1): + value = -math_pi/2 + count = 1 + for y in range(1,300,2): + if(count % 2 == 1): + value -= (float(1)/float(((x ** y)*y))) + else: + value += (float(1)/float(((x ** y)*y))) + count += 1 + return value + # arc tan -1 < x < 1 + else: + value = x + count = 1 + for y in range(3,300,2): + if(count % 2 == 1): + value -= (x ** y)/y + else: + value += (x ** y)/y + count += 1 + return value + +def math_asin(x): + if(x < 1 and x > -1): + value = x + numerator = 1 + denominator = 2 + for y in range(3,300,2): + value += (float(numerator)/float(denominator)) * ((x ** y) /float(y)) + numerator *= y + denominator *= (y + 1) + return value + else: + raise ValueError, "math domain error, 'x' cannot be >= 1 and 'x' cannot be <= -1 for math_asin" + +def math_acos(x): + if(x < 1 and x > -1): + return math_pi/2 - math_asin(x) + else: + raise ValueError, "math domain error, 'x' cannot be >= 1 and 'x' cannot be <= -1 for math_acos" + # square root function using the Newton-Raphson method def math_sqrt(x): if(x == 0): return x if(x < 0): - x = -x + raise ValueError, "math domain error, 'x' cannot be < 1 for math_sqrt" k = 1.0 while((k*k - x) > 0.00000000001 or (x - k * k) > 0.00000000001): k = (k + x / k) / 2