123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- if(!dojo._hasResource["dojox.calc._Executor"]){
- dojo._hasResource["dojox.calc._Executor"] = true;
- dojo.provide("dojox.calc._Executor");
- dojo.require("dijit._Templated");
- dojo.require("dojox.math._base");
- dojo.experimental("dojox.calc._Executor");
- (function(){
- var calcEnv;
- if(!("pow" in dojox.calc)){
- dojox.calc.pow = function(/*Number*/ base, /*Number*/ exponent){
-
-
-
- function isInt(n){
- return Math.floor(n) == n;
- }
- if(base >= 0 || isInt(exponent)){
- return Math.pow(base, exponent);
- }else{
- var inv = 1 / exponent;
-
- return (isInt(inv) && (inv & 1)) ? -Math.pow(-base, exponent) : NaN;
- }
- };
- }
- dojo.declare(
- "dojox.calc._Executor",
- [dijit._Widget, dijit._Templated],
- {
-
-
-
-
- templateString: '<iframe src="' +
- dojo.moduleUrl("dojox.calc","_ExecutorIframe.html") +
- '" style="display:none;" onload="if(arguments[0] && arguments[0].Function)'+dijit._scopeName+'.byNode(this)._onLoad(arguments[0])"></iframe>',
- _onLoad: function(env){
-
-
-
- calcEnv = env;
- env.outerPrompt = window.prompt;
-
- env.dojox = {math: {}};
- for(var f in dojox.math){ env.dojox.math[f] = dojo.hitch(dojox.math, f); }
- if("toFrac" in dojox.calc){
- env.toFracCall = dojo.hitch(dojox.calc, 'toFrac');
- this.Function('toFrac', 'x', "return toFracCall(x)");
- }
- env.isJavaScriptLanguage = dojo.number.format(1.5, {pattern:'#.#'}) == "1.5";
- env.Ans = 0;
- env.pi = Math.PI;
- env.eps = Math.E;
- env.powCall = dojo.hitch(dojox.calc, 'pow');
-
-
- this.normalizedFunction('sqrt', 'x', "return Math.sqrt(x)");
- this.normalizedFunction('sin', 'x', "return Math.sin(x)");
- this.normalizedFunction('cos', 'x', "return Math.cos(x)");
- this.normalizedFunction('tan', 'x', "return Math.tan(x)");
- this.normalizedFunction('asin', 'x', "return Math.asin(x)");
- this.normalizedFunction('acos', 'x', "return Math.acos(x)");
- this.normalizedFunction('atan', 'x', "return Math.atan(x)");
- this.normalizedFunction('atan2', 'y, x', "return Math.atan2(y, x)");
- this.normalizedFunction('Round', 'x', "return Math.round(x)");
- this.normalizedFunction('Int', 'x', "return Math.floor(x)");
- this.normalizedFunction('Ceil', 'x', "return Math.ceil(x)");
- this.normalizedFunction('ln', 'x', "return Math.log(x)");
- this.normalizedFunction('log', 'x', "return Math.log(x)/Math.log(10)");
- this.normalizedFunction('pow', 'x, y', "return powCall(x,y)");
- this.normalizedFunction('permutations', 'n, r', "return dojox.math.permutations(n, r);");
- this.normalizedFunction('P', 'n, r', "return dojox.math.permutations(n, r);");
- this.normalizedFunction('combinations', 'n, r', "return dojox.math.combinations(n, r);");
- this.normalizedFunction('C', 'n, r', "return dojox.math.combinations(n, r)");
- this.normalizedFunction('toRadix', 'number, baseOut', "if(!baseOut){ baseOut = 10; } if(typeof number == 'string'){ number = parseFloat(number); }return number.toString(baseOut);");
- this.normalizedFunction('toBin', 'number', "return toRadix(number, 2)");
- this.normalizedFunction('toOct', 'number', "return toRadix(number, 8)");
- this.normalizedFunction('toHex', 'number', "return toRadix(number, 16)");
- this.onLoad();
- },
- onLoad: function(){
-
-
-
- },
- Function: function(name, args, body){
-
-
-
-
-
-
-
- return dojo.hitch(calcEnv, calcEnv.Function.apply(calcEnv, arguments));
- },
- normalizedFunction: function(name, args, body){
- return dojo.hitch(calcEnv, calcEnv.normalizedFunction.apply(calcEnv, arguments));
- },
- deleteFunction: function(name){
- calcEnv[name] = undefined;
- delete calcEnv[name];
- },
- eval: function(text){
-
-
-
-
-
- return calcEnv.eval.apply(calcEnv, arguments);
- },
- destroy: function(){
- this.inherited(arguments);
- calcEnv = null;
- }
- });
- })();
- (function(){
- var magicBigInt = (1 << 30) - 35;
- dojo.mixin(dojox.calc, {
- approx: function(r){
-
-
- if(typeof r == "number"){
- return Math.round(r * magicBigInt) / magicBigInt;
- }
- return r;
- }
- });
- })();
- }
|