| 
									
										
										
										
											2020-07-26 04:46:48 +00:00
										 |  |  | <blocks app="Snap! 6, https://snap.berkeley.edu" version="1"><block-definition s="USE BIGNUMS %'bool'" type="command" category="operators"><comment x="0" y="0" w="303.3333333333333" collapsed="false">call with True to turn on the entire Scheme numeric tower, including infinite-precision integers, exact rationals, and complex numbers; call with False to restore native JavaScript arithmetic.</comment><header></header><code></code><translations>pt:altera utilização de aritmética do Scheme para _
</translations><inputs><input type="%b"></input></inputs><script><block s="doDeclareVariables"><list><l>isDone</l></list></block><block s="doSetVar"><l>isDone</l><block s="evaluate"><block s="reportJSFunction"><list><l>useBigNums</l></list><l>var done = false;

function initialize (callback) {
    var bigScript = document.createElement('script');
    bigScript.src = '//snap.berkeley.edu/snap/libraries/biginteger.js';
    bigScript.onload = loadScheme;
    document.head.appendChild(bigScript);

    function loadScheme () {
        var schemeScript = document.createElement('script');
        schemeScript.src = '//snap.berkeley.edu/snap/libraries/schemeNumber.js';
        schemeScript.onload = finish;
        document.head.appendChild(schemeScript);
    }

    function finish () {
        makeGlobalObject();
        callback();
    }
}

function makeGlobalObject () {
    window.bigNumbers = {
        originalEvaluate: InputSlotMorph.prototype.evaluate,
        originalChangeVar: VariableFrame.prototype.changeVar,
        originalPrims: {
            reportBasicSum: Process.prototype.reportBasicSum,
            reportBasicDifference: Process.prototype.reportBasicDifference,
            reportBasicProduct: Process.prototype.reportBasicProduct,
            reportBasicQuotient: Process.prototype.reportBasicQuotient,
            reportBasicPower: Process.prototype.reportBasicPower,
            reportBasicModulus: Process.prototype.reportBasicModulus,
            reportBasicRandom: Process.prototype.reportBasicRandom,
            reportBasicLessThan: Process.prototype.reportBasicLessThan,
            reportBasicGreaterThan: Process.prototype.reportBasicGreaterThan,
            reportEquals: Process.prototype.reportEquals,
            reportIsIdentical: Process.prototype.reportIsIdentical,
            reportMonadic: Process.prototype.reportMonadic
        }
    };
}

function loadBlocks () {
    var fn = SchemeNumber.fn;
    var originalPrims = window.bigNumbers.originalPrims;
    if (useBigNums) {
        InputSlotMorph.prototype.evaluate = function () {
            var contents = this.contents();
            if (this.constant) {
                return this.constant;
            }
            if (this.isNumeric) {
                return parseNumber(contents.text || '0');
            }
            return contents.text;
        };
        VariableFrame.prototype.changeVar = function (name, delta, sender) {
            var frame = this.find(name),
                value,
                newValue;
            if (frame) {
                value = parseNumber(frame.vars[name].value);
                newValue = Number.isNaN(value) ? delta : fn['+'](value, parseNumber(delta));
                if (sender instanceof SpriteMorph &&
                        (frame.owner instanceof SpriteMorph) &&
                        (sender !== frame.owner)) {
                    sender.shadowVar(name, newValue);
                } else {
                    frame.vars[name].value = newValue;
                }

            }
        };
        Object.assign(Process.prototype, {
            reportBasicSum: function (a, b) {
                a = parseNumber(a);
                b =  |