Commit d525c647 authored by nathan1505's avatar nathan1505
Browse files

Version 2.0: TrigSin and TrigCos are implemented and passed the test cases

parent 71da54e0
No preview for this file type
......@@ -2,6 +2,8 @@ package trigCode;
public class Trig {
static double PI = 3.1415926535;
public Integer sum(int a, int b) {
// TODO Auto-generated method stub
return a + b;
......@@ -9,12 +11,46 @@ public class Trig {
// takes in a double that is in radians or degrees
public double trigCos(double x) {
return x;
// acts as a variable to hold temporary values
double xTerm = 1.0;
// carries the sum of the value throughout
double sum = 1.0;
// the denominator of the expression
double denom;
// this makes sure that x is a value between -2*PI and 2*PI
x = x % (2 * PI);
// this loop calculates the value of the cosine of x
for(int i = 1; xTerm != 0.0; i++) {
denom = 2 * i * (2 * i - 1);
xTerm = -xTerm * x * x/denom;
sum = sum + xTerm;
}
return sum;
}
// takes in a double value that is in radians or degrees
public double trigSin(double x) {
return x;
// this makes sure that x is a value between -2*PI and 2*PI
x = x % (2 * PI);
// acts as a variable to hold temporary values
double xTerm = x;
// carries the sum of the value throughout
double sum = x;
// the denominator of the expression
double denom;
// use this for loop to determine the actual value of sin(x)
for(int i = 1; xTerm != 0.0; i++) {
denom = 2 * i * (2 * i + 1);
xTerm = -xTerm * x * x/denom;
sum = sum + xTerm;
}
return sum;
}
// calculates the tan of x (that is in degrees or radians)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment