Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


<head>
<script async src="trigocal.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="assets/trigo.png" type="image/icon">
Expand Down Expand Up @@ -202,7 +201,7 @@ <h2>Trigonometric functions</h2>
<hr width=90% color="#E5C480">
<a href="mailto:abhijeetkr.sci@gmail.com"><img src="assets/feedback.png" height="65" width="200"></a>

<script src="trigocal.js"></script>
<script src="trigocal.js" defer></script>
<script>
function calcright() {
var i1 = document.getElementById("degtype1").selectedIndex;
Expand Down
82 changes: 23 additions & 59 deletions trigocal.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,45 @@
function setfocus() {
document.calcform.x.focus();
document.getElementById("x").focus();
}

function calc() {
x = document.calcform.x.value;
y = calcfunc(x);
y = roundresult(y);
document.calcform.y.value = y
}
let x = parseFloat(document.getElementById("x").value);

function calc_a() {
x = document.calcform2.x.value;
y = calcfunc_a(x);
y = roundresult(y);
document.calcform2.y.value = y
}
if (isNaN(x)) {
document.getElementById("y").value = "Invalid input";
return;
}

function calc3() {
x1 = document.calcform.x.value;
x2 = document.calcform.x2.value;
y = calcfunc(x1, x2);
y = roundresult(y);
document.calcform.y.value = y;
}
let func = document.getElementById("func").value;
let y;

function calc4() {
a = document.calcform.x.value;
b = document.calcform.x2.value;
c = document.calcform.x3.value;
d = b * b - 4 * a * c;
document.calcform.y0.value = roundresult(d);
if (d >= 0) {
document.calcform.y1.value = roundresult((-b + Math.sqrt(d)) / (2 * a));
document.calcform.y2.value = roundresult((-b - Math.sqrt(d)) / (2 * a));
} else {
re = roundresult(-b / (2 * a));
im = roundresult(Math.sqrt(-d) / (2 * a));
document.calcform.y1.value = re + ' + i' + im;
document.calcform.y2.value = re + ' - i' + im;
}
b = -b;
document.calcform.y3.value = '(' + b.toString() + ' \xb1 \u221A(' + d.toString() + ')) / (2\xd7' + a.toString() + ')';
}
if (func === "sin") y = Math.sin(x);
else if (func === "cos") y = Math.cos(x);
else if (func === "tan") y = Math.tan(x);
else if (func === "csc") y = 1 / Math.sin(x);
else if (func === "sec") y = 1 / Math.cos(x);
else if (func === "cot") y = 1 / Math.tan(x);

function calc5() {
x = document.calcform.x.value;
y = calcfunc(x);
y = roundresult(y);
if (x > 0) y = '\u00B1' + y;
document.calcform.y.value = y
document.getElementById("y").value = y;
}

function calc6() {
x1 = document.calcform.x.value;
x2 = document.calcform.x2.value;
val = x2;
if (x2 < 0) val = -val;
y = calcfunc(x1, val);
function calc_a() {
let x = parseFloat(document.getElementById("x").value);
let y = calcfunc_a(x);
y = roundresult(y);
if (x2 > 0 && (x1 / 2) == Math.round(x1 / 2)) y = '\u00B1' + y;
if (x2 < 0) {
if ((x1 / 2) == Math.round(x1 / 2))
y = 'NaN';
else
y = -y;
}
document.calcform.y.value = y;
document.getElementById("y").value = y;
}


function str2num(s) {
s = s.toString().trim().replace(/(\d)(\s+)(?=\d)/gm, "$1+").replace(/[^-()\d/*+.]/g, '');
if (s == '') return 0;
return Function('"use strict";return (' + s + ')')();
}

function roundresult(x) {
y = parseFloat(x);
let y = parseFloat(x);
y = roundnum(y, 10);
return y;
}
Expand All @@ -87,7 +51,7 @@ function roundnum(x, p) {
var y = String(m);
i = y.indexOf('e');
if (i == -1) i = y.length;
j = y.indexOf('.');
let j = y.indexOf('.');
if (i > j && j != -1) {
while (i > 0) {
if (y.charAt(--i) == '0')
Expand All @@ -107,7 +71,7 @@ function roundnum2(x, p) {
var m = n.toFixed(p);
var y = String(m);
i = y.length;
j = y.indexOf('.');
let j = y.indexOf('.');
if (i > j && j != -1) {
while (i > 0) {
if (y.charAt(--i) == '0')
Expand Down