trying to make simple numerics a bit faster
This commit is contained in:
parent
97c11cffba
commit
7b31b119a5
|
@ -18,6 +18,7 @@
|
|||
'-
|
||||
'*
|
||||
'/
|
||||
'zero?
|
||||
'add1
|
||||
'sub1
|
||||
'abs
|
||||
|
@ -127,6 +128,7 @@
|
|||
'-
|
||||
'*
|
||||
'/
|
||||
'zero?
|
||||
'add1
|
||||
'sub1
|
||||
'<
|
||||
|
@ -178,6 +180,12 @@
|
|||
[else
|
||||
(make-IncorrectArity (make-ArityAtLeast 1))])]
|
||||
|
||||
[(eq? prim 'zero?)
|
||||
(cond [(= arity 1)
|
||||
(list 'number)]
|
||||
[else
|
||||
(make-IncorrectArity (make-ArityAtLeast 1))])]
|
||||
|
||||
[(eq? prim 'add1)
|
||||
(cond [(= arity 1)
|
||||
(list 'number)]
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
[(-)
|
||||
(cond [(empty? (rest checked-operands))
|
||||
(assemble-binop-chain "plt.baselib.numbers.subtract" (cons "0" checked-operands))]
|
||||
(format "RT.checkedNegate(M, ~a)" (first operands))]
|
||||
[else
|
||||
(assemble-binop-chain "plt.baselib.numbers.subtract" checked-operands)])]
|
||||
|
||||
|
@ -51,6 +51,9 @@
|
|||
[(/)
|
||||
(assemble-binop-chain "plt.baselib.numbers.divide" checked-operands)]
|
||||
|
||||
[(zero?)
|
||||
(format "RT.checkedIsZero(M, ~a)" (first operands))]
|
||||
|
||||
[(add1)
|
||||
(format "RT.checkedAdd1(M, ~a)" (first operands))]
|
||||
|
||||
|
|
|
@ -805,6 +805,13 @@
|
|||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
var checkedIsZero = function(M, n) {
|
||||
if (typeof(n) === 'number') { return n===0; }
|
||||
return plt.baselib.numbers.equals(
|
||||
testArgument(M, 'number', isNumber, n, 0, 'zero?'),
|
||||
0);
|
||||
};
|
||||
|
||||
var checkedAdd1 = function(M, n) {
|
||||
if (typeof(n) === 'number' && n < 9e15) { return n+1; }
|
||||
return plt.baselib.numbers.add(
|
||||
|
@ -815,9 +822,17 @@
|
|||
var checkedSub1 = function(M, n) {
|
||||
if (typeof(n) === 'number' && n > -9e15) { return n-1; }
|
||||
return plt.baselib.numbers.subtract(
|
||||
testArgument(M, 'number', isNumber, n, 0, 'add1'),
|
||||
testArgument(M, 'number', isNumber, n, 0, 'sub1'),
|
||||
1);
|
||||
};
|
||||
|
||||
var checkedNegate = function(M, n) {
|
||||
if (typeof(n) === 'number') { return -n; }
|
||||
return plt.baselib.numbers.subtract(
|
||||
0,
|
||||
testArgument(M, 'number', isNumber, n, 0, '-'));
|
||||
};
|
||||
|
||||
var checkedCar = function(M, v) {
|
||||
if (isPair(v)) { return v.first; }
|
||||
raiseArgumentTypeError(M, 'car', 'pair', 0, v);
|
||||
|
@ -829,9 +844,6 @@
|
|||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -967,8 +979,10 @@
|
|||
exports['checkClosureAndArity'] = checkClosureAndArity;
|
||||
exports['checkPrimitiveArity'] = checkPrimitiveArity;
|
||||
|
||||
exports['checkedIsZero'] = checkedIsZero;
|
||||
exports['checkedAdd1'] = checkedAdd1;
|
||||
exports['checkedSub1'] = checkedSub1;
|
||||
exports['checkedNegate'] = checkedNegate;
|
||||
exports['checkedCar'] = checkedCar;
|
||||
exports['checkedCdr'] = checkedCdr;
|
||||
}(this.plt, this.plt.baselib));
|
Loading…
Reference in New Issue
Block a user