-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
104 lines (86 loc) · 2.95 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function joinWeb() {
// SIN
document.getElementById("sin-input").value = 0;
var sinX = document.getElementById("sin-input").value;
document.getElementById("sin-result").innerHTML = '<p style="font-size: 35px">=' + sin(sinX) + '</p>';
// COS
document.getElementById("cos-input").value = 0;
var cosX = document.getElementById("cos-input").value;
document.getElementById("cos-result").innerHTML = '<p style="font-size: 35px">=' + cos(cosX) + '</p>';
// TAN
document.getElementById("tan-input").value = 0;
var tanX = document.getElementById("tan-input").value;
document.getElementById("tan-result").innerHTML = '<p style="font-size: 35px">=' + tan(tanX) + '</p>';
}
function decimalTheorem(d) {
var temp = d.length;
var tempText = d;
if (d.includes('.') == true) {
while(true) {
temp = temp-1;
if (d.charAt(temp) == 0) {
tempText = d.substr(0, temp);
}else if (d.charAt(temp) == "."){
tempText = d.substr(0, temp);
break;
}else{
break;
}
}
}
return tempText;
}
// SIN
function sin(X) {
if (Math.sin(X * Math.PI / 180).toFixed(8) == "NaN") {
return "null";
}else{
if (decimalTheorem(Math.sin(X * Math.PI / 180).toFixed(8)) == -0) {
return 0;
}else{
return decimalTheorem(Math.sin(X * Math.PI / 180).toFixed(8));
}
}
}
$("#sin-input").on("propertychange change paste input", function() {
var sinX = document.getElementById("sin-input").value;
document.getElementById("sin-result").innerHTML = '<p style="font-size: 35px">=' + sin(sinX) + '</p>';
});
// COS
function cos(X) {
if (Math.cos(X * Math.PI / 180).toFixed(8) == "NaN") {
return "null";
}else{
if (decimalTheorem(Math.cos(X * Math.PI / 180).toFixed(8)) == -0) {
return 0;
}else{
return decimalTheorem(Math.cos(X * Math.PI / 180).toFixed(8));
}
}
}
$("#cos-input").on("propertychange change paste input", function() {
var cosX = document.getElementById("cos-input").value;
document.getElementById("cos-result").innerHTML = '<p style="font-size: 35px">=' + cos(cosX) + '</p>';
});
// TAN
function tan(X) {
var tanResult = sin(X)/cos(X)
if (tanResult.toFixed(8) == "NaN") {
return "null";
}else if (tanResult == Infinity){
return Infinity;
}else{
if (decimalTheorem(tanResult.toFixed(8)) == -0) {
return 0;
}else if (decimalTheorem(tanResult.toFixed(8)) == -Infinity){
return Infinity;
}else{
return decimalTheorem(tanResult.toFixed(8));
}
}
}
$("#tan-input").on("propertychange change paste input", function() {
var tanX = document.getElementById("tan-input").value;
document.getElementById("tan-result").innerHTML = '<p style="font-size: 35px">=' + tan(tanX) + '</p>';
});
joinWeb()