Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * What this script does is
- * by some sort of mathematic rules,
- * normalizes numbers for use in trigonometry
- * and pretty much gives you their values as well.
- */ /*
- Time stands still when you're with me
- How can I make you see
- your crazy antics make me want to scream
- your name so loud till my throat starts to bleed
- */
- var d = { // Logging object, extremely useful & reusable
- OUTPUT: 1,
- ERRORS: 2,
- LOGGING: 4,
- flags: this.OUTPUT | this.ERRORS | this.LOGGING,
- // Order by importance of error: 0 lowest, X highest.
- ERRTHRES: 2, // Error threshold. Lower than this is ignored.
- // Order by verbosity of logging: 0 lowest, X highest.
- LOGTHRES: 6, // Logging threshold. HIGHER than this ignored.
- log: function(data, level) {
- if(!(this.flags & this.LOGGING) || level < this.LOGTHRES) return;
- if (!level)
- level = 0;
- console.log("[DEBUG " + level + "]: "+ data);
- },
- err: function(data, level) {
- if(!(this.flags & this.ERRORS) || level > this.ERRTHRES) return;
- if (!level)
- level = 0;
- console.log("[ERROR "+ level + "]: "+ data);
- },
- out: function(data) {
- if(!(this.flags & this.OUTPUT)) return;
- console.log("[OUTPUT]: "+ data);
- }
- }
- // angles go in degrees
- function normalizeTrig(angle, type) {
- if("sincostan".indexOf(type) == -1)
- d.err("Type is not a trig function", 3);
- while (angle > 90)
- {
- if (angle < 180) {
- angle = angle - 90;
- angle = 90 - angle;
- if (type == "cos" || type == "tan")
- angle = -angle;
- d.log ("angle is now: " + angle, 5);
- break;
- }
- else if(angle > 180 && angle < 270) {
- angle = angle - 180;
- if (type == "cos" || type == "sin")
- angle = -angle;
- d.log ("angle is now: " + angle, 5);
- break;
- }
- else if(angle > 270 && angle < 360) {
- angle = angle - 270;
- angle = 90 - angle;
- if (type == "sin" || type == "tan")
- angle = -angle;
- d.log ("angle is now: " + angle, 5);
- break;
- }
- else if(angle > 360) {
- angle -= 360;
- d.log ("angle is now: " + angle, 5);
- }
- }
- return angle;
- }
- function init() {
- var number, i;
- console.log("Started.");
- console.log("Logging flags: "+
- (d.LOGGING ? "LOGGING " : "") +
- (d.ERRORS ? "ERRORS " : "") +
- (d.OUTPUT ? "OUTPUT " : ""));
- console.log("Now doing maths.");
- for (i=0;i<100;i++) {
- number = Math.random() * 10000;
- console.log("sin " + number + " = sin " + normalizeTrig(number, "sin"));
- }
- }
- init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement