1.1 --- a/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java Tue Feb 26 16:54:16 2013 +0100
1.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java Wed Feb 27 16:24:42 2013 +0100
1.3 @@ -26,55 +26,63 @@
1.4 * @author Jaroslav Tulach <jtulach@netbeans.org>
1.5 */
1.6 public class LongArithmeticTest {
1.7 -
1.8 +
1.9 private static long add(long x, long y) {
1.10 return (x + y);
1.11 }
1.12 -
1.13 +
1.14 private static long sub(long x, long y) {
1.15 return (x - y);
1.16 }
1.17 -
1.18 +
1.19 private static long mul(long x, long y) {
1.20 return (x * y);
1.21 }
1.22 -
1.23 +
1.24 private static long div(long x, long y) {
1.25 return (x / y);
1.26 }
1.27 -
1.28 +
1.29 private static long mod(long x, long y) {
1.30 return (x % y);
1.31 }
1.32 -
1.33 +
1.34 private static long neg(long x) {
1.35 return (-x);
1.36 }
1.37 -
1.38 +
1.39 private static long shl(long x, int b) {
1.40 return (x << b);
1.41 }
1.42 -
1.43 +
1.44 private static long shr(long x, int b) {
1.45 return (x >> b);
1.46 }
1.47 -
1.48 +
1.49 private static long ushr(long x, int b) {
1.50 return (x >>> b);
1.51 }
1.52 -
1.53 +
1.54 private static long and(long x, long y) {
1.55 return (x & y);
1.56 }
1.57 -
1.58 +
1.59 private static long or(long x, long y) {
1.60 return (x | y);
1.61 }
1.62 -
1.63 +
1.64 private static long xor(long x, long y) {
1.65 return (x ^ y);
1.66 }
1.67 -
1.68 +
1.69 + private static float fadd(float x, float y) {
1.70 + return x + y;
1.71 + }
1.72 +
1.73 + private static double dadd(double x, double y) {
1.74 + return x + y;
1.75 + }
1.76 +
1.77 public static int compare(long x, long y, int zero) {
1.78 final int xyResult = compareL(x, y, zero);
1.79 final int yxResult = compareL(y, x, zero);
1.80 @@ -106,15 +114,15 @@
1.81
1.82 return (trueCount == 1) ? result : -2;
1.83 }
1.84 -
1.85 +
1.86 @Compare public long conversion() {
1.87 return Long.MAX_VALUE;
1.88 }
1.89 -
1.90 +
1.91 @Compare public long negate1() {
1.92 return neg(0x00fa37d7763e0ca1l);
1.93 }
1.94 -
1.95 +
1.96 @Compare public long negate2() {
1.97 return neg(0x80fa37d7763e0ca1l);
1.98 }
1.99 @@ -134,11 +142,11 @@
1.100 @Compare public long addMaxLongAndMaxLong() {
1.101 return add(Long.MAX_VALUE, Long.MAX_VALUE);
1.102 }
1.103 -
1.104 +
1.105 @Compare public long subMinLongAndMinLong() {
1.106 return sub(Long.MIN_VALUE, Long.MIN_VALUE);
1.107 }
1.108 -
1.109 +
1.110 @Compare public long subMinLongAndMaxLong() {
1.111 return sub(Long.MIN_VALUE, Long.MAX_VALUE);
1.112 }
1.113 @@ -146,23 +154,23 @@
1.114 @Compare public long multiplyMaxLong() {
1.115 return mul(Long.MAX_VALUE, 2l);
1.116 }
1.117 -
1.118 +
1.119 @Compare public long multiplyMaxLongAndMaxLong() {
1.120 return mul(Long.MAX_VALUE, Long.MAX_VALUE);
1.121 }
1.122 -
1.123 +
1.124 @Compare public long multiplyMinLong() {
1.125 return mul(Long.MIN_VALUE, 2l);
1.126 }
1.127 -
1.128 +
1.129 @Compare public long multiplyMinLongAndMinLong() {
1.130 return mul(Long.MIN_VALUE, Long.MIN_VALUE);
1.131 }
1.132 -
1.133 +
1.134 @Compare public long multiplyPrecision() {
1.135 return mul(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
1.136 }
1.137 -
1.138 +
1.139 @Compare public long divideSmallPositiveNumbers() {
1.140 return div(0xabcdef, 0x123);
1.141 }
1.142 @@ -251,6 +259,22 @@
1.143 return mod(0x7fff800000000000l, 0x800000000001l);
1.144 }
1.145
1.146 + @Compare public long conversionFromFloatPositive() {
1.147 + return (long) fadd(2, 0.6f);
1.148 + }
1.149 +
1.150 + @Compare public long conversionFromFloatNegative() {
1.151 + return (long) fadd(-2, -0.6f);
1.152 + }
1.153 +
1.154 + @Compare public long conversionFromDoublePositive() {
1.155 + return (long) dadd(0x20ffff0000L, 0.6);
1.156 + }
1.157 +
1.158 + @Compare public long conversionFromDoubleNegative() {
1.159 + return (long) dadd(-0x20ffff0000L, -0.6);
1.160 + }
1.161 +
1.162 @Compare public boolean divByZeroThrowsArithmeticException() {
1.163 try {
1.164 div(1, 0);
1.165 @@ -272,63 +296,63 @@
1.166 @Compare public long shiftL1() {
1.167 return shl(0x00fa37d7763e0ca1l, 5);
1.168 }
1.169 -
1.170 +
1.171 @Compare public long shiftL2() {
1.172 return shl(0x00fa37d7763e0ca1l, 32);
1.173 }
1.174 -
1.175 +
1.176 @Compare public long shiftL3() {
1.177 return shl(0x00fa37d7763e0ca1l, 45);
1.178 }
1.179 -
1.180 +
1.181 @Compare public long shiftR1() {
1.182 return shr(0x00fa37d7763e0ca1l, 5);
1.183 }
1.184 -
1.185 +
1.186 @Compare public long shiftR2() {
1.187 return shr(0x00fa37d7763e0ca1l, 32);
1.188 }
1.189 -
1.190 +
1.191 @Compare public long shiftR3() {
1.192 return shr(0x00fa37d7763e0ca1l, 45);
1.193 }
1.194 -
1.195 +
1.196 @Compare public long uShiftR1() {
1.197 return ushr(0x00fa37d7763e0ca1l, 5);
1.198 }
1.199 -
1.200 +
1.201 @Compare public long uShiftR2() {
1.202 return ushr(0x00fa37d7763e0ca1l, 45);
1.203 }
1.204 -
1.205 +
1.206 @Compare public long uShiftR3() {
1.207 return ushr(0xf0fa37d7763e0ca1l, 5);
1.208 }
1.209 -
1.210 +
1.211 @Compare public long uShiftR4() {
1.212 return ushr(0xf0fa37d7763e0ca1l, 45);
1.213 }
1.214 -
1.215 +
1.216 @Compare public long and1() {
1.217 return and(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
1.218 }
1.219 -
1.220 +
1.221 @Compare public long or1() {
1.222 return or(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
1.223 }
1.224 -
1.225 +
1.226 @Compare public long xor1() {
1.227 return xor(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
1.228 }
1.229 -
1.230 +
1.231 @Compare public long xor2() {
1.232 return xor(0x00fa37d7763e0ca1l, 0x00000000ff00123el);
1.233 }
1.234 -
1.235 +
1.236 @Compare public long xor3() {
1.237 return xor(0x00000000763e0ca1l, 0x00000000ff00123el);
1.238 }
1.239 -
1.240 +
1.241 @Compare public int compareSameNumbers() {
1.242 return compare(0x0000000000000000l, 0x0000000000000000l, 0);
1.243 }