Wed, 31 Dec 2014 07:53:36 +0100
Correct small whitespace inconsistency, lost while renaming variables.
michael@0 | 1 | // Copyright 2009 the Sputnik authors. All rights reserved. |
michael@0 | 2 | // This code is governed by the BSD license found in the LICENSE file. |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * The result of a ECMAScript floating-point remainder operation is determined by the rules of IEEE arithmetics |
michael@0 | 6 | * |
michael@0 | 7 | * @path ch11/11.5/11.5.3/S11.5.3_A4_T7.js |
michael@0 | 8 | * @description If operands neither an infinity, nor a zero, nor NaN, return x - truncate(x / y) * y |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | function truncate(x) { |
michael@0 | 12 | if (x > 0) { |
michael@0 | 13 | return Math.floor(x); |
michael@0 | 14 | } else { |
michael@0 | 15 | return Math.ceil(x); |
michael@0 | 16 | } |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | //CHECK#1 |
michael@0 | 20 | x = 1.3; |
michael@0 | 21 | y = 1.1; |
michael@0 | 22 | if (x % y !== 0.19999999999999996) { |
michael@0 | 23 | $ERROR('#1: x = 1.3; y = 1.1; x % y === 0.19999999999999996. Actual: ' + (x % y)); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | //CHECK#2 |
michael@0 | 27 | x = -1.3; |
michael@0 | 28 | y = 1.1; |
michael@0 | 29 | if (x % y !== -0.19999999999999996) { |
michael@0 | 30 | $ERROR('#2: x = -1.3; y = 1.1; x % y === -0.19999999999999996. Actual: ' + (x % y)); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | //CHECK#3 |
michael@0 | 34 | x = 1.3; |
michael@0 | 35 | y = -1.1; |
michael@0 | 36 | if (x % y !== 0.19999999999999996) { |
michael@0 | 37 | $ERROR('#3: x = 1.3; y = -1.1; x % y === 0.19999999999999996. Actual: ' + (x % y)); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | //CHECK#4 |
michael@0 | 41 | x = -1.3; |
michael@0 | 42 | y = -1.1; |
michael@0 | 43 | if (x % y !== -0.19999999999999996) { |
michael@0 | 44 | $ERROR('#4: x = -1.3; y = -1.1; x % y === -0.19999999999999996. Actual: ' + (x % y)); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | //CHECK#5 |
michael@0 | 48 | x = 1.3; |
michael@0 | 49 | y = 1.1; |
michael@0 | 50 | if (x % y !== x - truncate(x / y) * y) { |
michael@0 | 51 | $ERROR('#5: x = 1.3; y = 1.1; x % y === x - truncate(x / y) * y. Actual: ' + (x % y)); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | //CHECK#6 |
michael@0 | 55 | x = -1.3; |
michael@0 | 56 | y = 1.1; |
michael@0 | 57 | if (x % y !== x - truncate(x / y) * y) { |
michael@0 | 58 | $ERROR('#6: x = -1.3; y = 1.1; x % y === x - truncate(x / y) * y. Actual: ' + (x % y)); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | //CHECK#7 |
michael@0 | 62 | x = 1.3; |
michael@0 | 63 | y = -1.1; |
michael@0 | 64 | if (x % y !== x - truncate(x / y) * y) { |
michael@0 | 65 | $ERROR('#7: x = 1.3; y = -1.1; x % y === x - truncate(x / y) * y. Actual: ' + (x % y)); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | //CHECK#8 |
michael@0 | 69 | x = -1.3; |
michael@0 | 70 | y = -1.1; |
michael@0 | 71 | if (x % y !== x - truncate(x / y) * y) { |
michael@0 | 72 | $ERROR('#8: x = -1.3; y = -1.1; x % y === x - truncate(x / y) * y. Actual: ' + (x % y)); |
michael@0 | 73 | } |
michael@0 | 74 |