]> git.parisson.com Git - pdf.js.git/commitdiff
Fix idiv and cvi. Add test case for idiv.
authorBrendan Dahl <brendan.dahl@gmail.com>
Fri, 30 Dec 2011 21:25:34 +0000 (13:25 -0800)
committerBrendan Dahl <brendan.dahl@gmail.com>
Fri, 30 Dec 2011 21:25:34 +0000 (13:25 -0800)
src/function.js
test/unit/function_spec.js

index 8a2d773a1e10a9e7c05252a32e39f46e88b7fbb0..e8158341ef2ffcc671727874a06dba58e0697fe3 100644 (file)
@@ -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();
index 55ba4684e31395bfb3ce62ad3523d36f1bc0e0b9..2a1dc0b75a4ebf8be9673096d1b1a56b7342c699 100644 (file)
@@ -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];