Last active
August 29, 2015 14:23
-
-
Save mathdoodle/81d48ed77c2f0b93736e to your computer and use it in GitHub Desktop.
Complex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"uuid": "d93b3de1-8008-46f3-b7b5-cfb0938102be", | |
"description": "Complex", | |
"dependencies": { | |
"DomReady": "latest", | |
"davinci-blade": "1.1.1" | |
}, | |
"operatorOverloading": true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<style> | |
/* STYLE-MARKER */ | |
</style> | |
<!-- SCRIPTS-MARKER --> | |
</head> | |
<body> | |
<pre id='output'></pre> | |
<script> | |
// CODE-MARKER | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DomReady.ready(function() { | |
try { | |
calculation(); | |
} | |
catch(e) { | |
function red(arg: any) { | |
return "<span style='color:red'>" + arg + "</span>"; | |
} | |
println(red(e.message)); | |
} | |
}); | |
/** | |
* Units of Measure and Operator Overloading | |
*/ | |
function calculation() { | |
showvar('blade.VERSION', blade.VERSION); | |
var cos = blade.universals.cos; | |
var cosh = blade.universals.cosh; | |
var exp = blade.universals.exp; | |
var norm = blade.universals.norm; | |
var quad = blade.universals.quad; | |
var sin = blade.universals.sin; | |
var sinh = blade.universals.sinh; | |
var unit = blade.universals.unit; | |
Math.log(3) | |
var zero = new blade.Complex(0, 0); | |
var one = new blade.Complex(1, 0); | |
var i = new blade.Complex(0, 1); | |
var z = new blade.Complex(1, 1); | |
var ipie = i * Math.PI | |
//showvar('exp(i * pi) + 1', (exp(ipie)+1).toFixed(4)); | |
println(); | |
//showvar('0', zero); | |
//showvar('1', one); | |
//showvar('i', i); | |
showvar('z', z); | |
println(); | |
//showvar('unit(0)', unit(zero).toFixed(4)); | |
//showvar('unit(1)', unit(one).toFixed(4)); | |
//showvar('unit(i)', unit(i).toFixed(4)); | |
showvar('unit(z)', unit(z).toFixed(4)); | |
println(); | |
showvar('exp(0)', exp(zero).toFixed(4)); | |
showvar('exp(1)', exp(one).toFixed(4)); | |
showvar('exp(i)', exp(i).toFixed(4)); | |
showvar('exp(z)', exp(z).toFixed(4)); | |
//println(); | |
//showvar('norm(0)', norm(zero)); | |
//showvar('norm(1)', norm(one)); | |
//showvar('norm(i)', norm(i)); | |
showvar('norm(z)', norm(z).toFixed(4)); | |
//println(); | |
//showvar('quad(0)', quad(zero)); | |
//showvar('quad(1)', quad(one)); | |
//showvar('quad(i)', quad(i)); | |
showvar('quad(z)', quad(z).toFixed(4)); | |
println(); | |
showvar('cos(0)', cos(zero)); | |
showvar('cos(1)', cos(one)); | |
showvar('cos(i)', cos(i)); | |
//println(); | |
showvar('cosh(0)', cosh(zero)); | |
showvar('cosh(1)', cosh(one)); | |
showvar('cosh(i)', cosh(i)); | |
showvar('cos(z)', cos(z).toFixed(4)); | |
showvar('cosh(z)', cosh(z).toFixed(4)); | |
showvar('sin(z)', sin(z).toFixed(4)); | |
showvar('sinh(z)', sinh(z).toFixed(4)); | |
} | |
/** | |
* Print the HTML string without a line ending. | |
*/ | |
function print(html: string): void { | |
var element = document.getElementById('output'); | |
element.innerHTML = element.innerHTML + html; | |
} | |
/** | |
* Print the HTML string and go to the next line. | |
*/ | |
function println(html?: string): void { | |
if (typeof html !== 'undefined') { | |
print(html + '\n'); | |
} | |
else { | |
print('\n'); | |
} | |
} | |
function showvar(name: string, value: any) { | |
println("<b>" + name + "</b> => " + value) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#output { | |
position: absolute; | |
left: 10px; | |
top: 10px; | |
font-size: 14pt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment