From 9de52f375dc3bfc56923f306f14be799a5123ed1 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Fri, 30 Dec 2011 13:25:34 -0800 Subject: [PATCH] Fix idiv and cvi. Add test case for idiv. --- src/function.js | 4 ++-- test/unit/function_spec.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/function.js b/src/function.js index 8a2d773a1..e8158341e 100644 --- a/src/function.js +++ b/src/function.js @@ -536,7 +536,7 @@ var PostScriptEvaluator = (function PostScriptEvaluatorClosure() { stack.push(Math.cos(a)); break; case 'cvi': - a |= stack.pop(); + a = stack.pop() | 0; stack.push(a); break; case 'cvr': @@ -583,7 +583,7 @@ var PostScriptEvaluator = (function PostScriptEvaluatorClosure() { case 'idiv': b = stack.pop(); a = stack.pop(); - stack.push(Math.floor(a / b)); + stack.push((a / b) | 0); break; case 'index': a = stack.pop(); diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js index 55ba4684e..2a1dc0b75 100644 --- a/test/unit/function_spec.js +++ b/test/unit/function_spec.js @@ -173,7 +173,16 @@ describe('function', function() { // TODO floor // TODO ge // TODO gt - // TODO idiv + it('divides to integer', function() { + var stack = evaluate('{ 2 3 idiv }'); + var expectedStack = [0]; + expect(stack).toMatchArray(expectedStack); + }); + it('divides to negative integer', function() { + var stack = evaluate('{ -2 3 idiv }'); + var expectedStack = [0]; + expect(stack).toMatchArray(expectedStack); + }); it('duplicates index', function() { var stack = evaluate('{ 4 3 2 1 2 index }'); var expectedStack = [4, 3, 2, 1, 3];