vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java
brancharithmetic
changeset 676 eecf6077ec4e
parent 669 3754580b6c67
child 680 7ffb635a5c4f
     1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java	Tue Feb 05 15:03:22 2013 +0100
     1.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java	Tue Feb 05 16:40:01 2013 +0100
     1.3 @@ -168,7 +168,7 @@
     1.4                  new byte[] { (byte)0x80, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }
     1.5          );
     1.6      }
     1.7 -    
     1.8 +
     1.9      @Test public void longNegate3() throws Exception {
    1.10          final long res = -0xfffffffffffffeddl;
    1.11          assertExec("Long negate",
    1.12 @@ -178,7 +178,6 @@
    1.13          );
    1.14      }
    1.15  
    1.16 -    
    1.17      @Test public void longAddOverflow() throws Exception {
    1.18          final long res = Long.MAX_VALUE + 1l;
    1.19          assertExec("Addition 1+MAX",
    1.20 @@ -278,7 +277,239 @@
    1.21              new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
    1.22          );
    1.23      }
    1.24 -    
    1.25 +
    1.26 +    @Test public void longDivideSmallPositiveNumbers() throws Exception {
    1.27 +        final long res = 0xabcdef / 0x123;
    1.28 +        assertExec("Division Small Positive Numbers",
    1.29 +            Numbers.class, "divL__J_3B_3B",
    1.30 +            Double.valueOf(res),
    1.31 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef },
    1.32 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x23 }
    1.33 +        );
    1.34 +    }
    1.35 +
    1.36 +    @Test public void longDivideSmallNegativeNumbers() throws Exception {
    1.37 +        final long res = -0xabcdef / -0x123;
    1.38 +        assertExec("Division Small Negative Numbers",
    1.39 +            Numbers.class, "divL__J_3B_3B",
    1.40 +            Double.valueOf(res),
    1.41 +            new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x11 },
    1.42 +            new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd }
    1.43 +        );
    1.44 +    }
    1.45 +
    1.46 +    @Test public void longDivideSmallMixedNumbers() throws Exception {
    1.47 +        final long res = 0xabcdef / -0x123;
    1.48 +        assertExec("Division Small Mixed Numbers",
    1.49 +            Numbers.class, "divL__J_3B_3B",
    1.50 +            Double.valueOf(res),
    1.51 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef },
    1.52 +            new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd }
    1.53 +        );
    1.54 +    }
    1.55 +
    1.56 +    @Test public void longDividePositiveNumbersOneDigitDenom()
    1.57 +            throws Exception {
    1.58 +        final long res = 0xabcdef0102ffffL / 0x654;
    1.59 +        assertExec("Division Positive Numbers One Digit Denom",
    1.60 +            Numbers.class, "divL__J_3B_3B",
    1.61 +            Double.valueOf(res),
    1.62 +            new byte[] { (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef, (byte)0x01, (byte)0x02, (byte)0xff, (byte)0xff },
    1.63 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x54 }
    1.64 +        );
    1.65 +    }
    1.66 +
    1.67 +    @Test public void longDivideNegativeNumbersOneDigitDenom()
    1.68 +            throws Exception {
    1.69 +        final long res = -0xabcdef0102ffffL / -0x654;
    1.70 +        assertExec("Division Negative Numbers One Digit Denom",
    1.71 +            Numbers.class, "divL__J_3B_3B",
    1.72 +            Double.valueOf(res),
    1.73 +            new byte[] { (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x10, (byte)0xfe, (byte)0xfd, (byte)0x00, (byte)0x01 },
    1.74 +            new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xf9, (byte)0xac }
    1.75 +        );
    1.76 +    }
    1.77 +
    1.78 +    @Test public void longDivideMixedNumbersOneDigitDenom()
    1.79 +            throws Exception {
    1.80 +        final long res = -0xabcdef0102ffffL / 0x654;
    1.81 +        assertExec("Division Mixed Numbers One Digit Denom",
    1.82 +            Numbers.class, "divL__J_3B_3B",
    1.83 +            Double.valueOf(res),
    1.84 +            new byte[] { (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x10, (byte)0xfe, (byte)0xfd, (byte)0x00, (byte)0x01 },
    1.85 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x54 }
    1.86 +        );
    1.87 +    }
    1.88 +
    1.89 +    @Test public void longDividePositiveNumbersMultiDigitDenom()
    1.90 +            throws Exception {
    1.91 +        final long res = 0x7ffefc003322aabbL / 0x89ab1000L;
    1.92 +        assertExec("Division Positive Numbers Multi Digit Denom",
    1.93 +            Numbers.class, "divL__J_3B_3B",
    1.94 +            Double.valueOf(res),
    1.95 +            new byte[] { (byte)0x7f, (byte)0xfe, (byte)0xfc, (byte)0x00, (byte)0x33, (byte)0x22, (byte)0xaa, (byte)0xbb },
    1.96 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x89, (byte)0xab, (byte)0x10, (byte)0x00 }
    1.97 +        );
    1.98 +    }
    1.99 +
   1.100 +    @Test public void longDivideNegativeNumbersMultiDigitDenom()
   1.101 +            throws Exception {
   1.102 +        final long res = -0x7ffefc003322aabbL / -0x123489ab1001L;
   1.103 +        assertExec("Division Negative Numbers Multi Digit Denom",
   1.104 +            Numbers.class, "divL__J_3B_3B",
   1.105 +            Double.valueOf(res),
   1.106 +            new byte[] { (byte)0x80, (byte)0x01, (byte)0x03, (byte)0xff, (byte)0xcc, (byte)0xdd, (byte)0x55, (byte)0x45 },
   1.107 +            new byte[] { (byte)0xff, (byte)0xff, (byte)0xed, (byte)0xcb, (byte)0x76, (byte)0x54, (byte)0xef, (byte)0xff }
   1.108 +        );
   1.109 +    }
   1.110 +
   1.111 +    @Test public void longDivideMixedNumbersMultiDigitDenom()
   1.112 +            throws Exception {
   1.113 +        final long res = 0x7ffefc003322aabbL / -0x38f49b0b7574e36L;
   1.114 +        assertExec("Division Mixed Numbers Multi Digit Denom",
   1.115 +            Numbers.class, "divL__J_3B_3B",
   1.116 +            Double.valueOf(res),
   1.117 +            new byte[] { (byte)0x7f, (byte)0xfe, (byte)0xfc, (byte)0x00, (byte)0x33, (byte)0x22, (byte)0xaa, (byte)0xbb },
   1.118 +            new byte[] { (byte)0xfc, (byte)0x70, (byte)0xb6, (byte)0x4f, (byte)0x48, (byte)0xa8, (byte)0xb1, (byte)0xca }
   1.119 +        );
   1.120 +    }
   1.121 +
   1.122 +    @Test public void longDivideWithOverflow() throws Exception {
   1.123 +        final long res = 0x8000fffe0000L / 0x8000ffffL;
   1.124 +        assertExec("Division With Overflow",
   1.125 +            Numbers.class, "divL__J_3B_3B",
   1.126 +            Double.valueOf(res),
   1.127 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0xff, (byte)0xfe, (byte)0x00, (byte)0x00 },
   1.128 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0xff, (byte)0xff }
   1.129 +        );
   1.130 +    }
   1.131 +
   1.132 +    @Test public void longDivideWithCorrection() throws Exception {
   1.133 +        final long res = 0x7fff800000000000L / 0x800000000001L;
   1.134 +        assertExec("Division With Correction",
   1.135 +            Numbers.class, "divL__J_3B_3B",
   1.136 +            Double.valueOf(res),
   1.137 +            new byte[] { (byte)0x7f, (byte)0xff, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
   1.138 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01 }
   1.139 +        );
   1.140 +    }
   1.141 +
   1.142 +    @Test public void longModuloSmallPositiveNumbers() throws Exception {
   1.143 +        final long res = 0xabcdef % 0x123;
   1.144 +        assertExec("Modulo Small Positive Numbers",
   1.145 +            Numbers.class, "modL__J_3B_3B",
   1.146 +            Double.valueOf(res),
   1.147 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef },
   1.148 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x23 }
   1.149 +        );
   1.150 +    }
   1.151 +
   1.152 +    @Test public void longModuloSmallNegativeNumbers() throws Exception {
   1.153 +        final long res = -0xabcdef % -0x123;
   1.154 +        assertExec("Modulo Small Negative Numbers",
   1.155 +            Numbers.class, "modL__J_3B_3B",
   1.156 +            Double.valueOf(res),
   1.157 +            new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x11 },
   1.158 +            new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd }
   1.159 +        );
   1.160 +    }
   1.161 +
   1.162 +    @Test public void longModuloSmallMixedNumbers() throws Exception {
   1.163 +        final long res = 0xabcdef % -0x123;
   1.164 +        assertExec("Modulo Small Mixed Numbers",
   1.165 +            Numbers.class, "modL__J_3B_3B",
   1.166 +            Double.valueOf(res),
   1.167 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef },
   1.168 +            new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd }
   1.169 +        );
   1.170 +    }
   1.171 +
   1.172 +    @Test public void longModuloPositiveNumbersOneDigitDenom()
   1.173 +            throws Exception {
   1.174 +        final long res = 0xabcdef0102ffffL % 0x654;
   1.175 +        assertExec("Modulo Positive Numbers One Digit Denom",
   1.176 +            Numbers.class, "modL__J_3B_3B",
   1.177 +            Double.valueOf(res),
   1.178 +            new byte[] { (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef, (byte)0x01, (byte)0x02, (byte)0xff, (byte)0xff },
   1.179 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x54 }
   1.180 +        );
   1.181 +    }
   1.182 +
   1.183 +    @Test public void longModuloNegativeNumbersOneDigitDenom()
   1.184 +            throws Exception {
   1.185 +        final long res = -0xabcdef0102ffffL % -0x654;
   1.186 +        assertExec("Modulo Negative Numbers One Digit Denom",
   1.187 +            Numbers.class, "modL__J_3B_3B",
   1.188 +            Double.valueOf(res),
   1.189 +            new byte[] { (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x10, (byte)0xfe, (byte)0xfd, (byte)0x00, (byte)0x01 },
   1.190 +            new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xf9, (byte)0xac }
   1.191 +        );
   1.192 +    }
   1.193 +
   1.194 +    @Test public void longModuloMixedNumbersOneDigitDenom()
   1.195 +            throws Exception {
   1.196 +        final long res = -0xabcdef0102ffffL % 0x654;
   1.197 +        assertExec("Modulo Mixed Numbers One Digit Denom",
   1.198 +            Numbers.class, "modL__J_3B_3B",
   1.199 +            Double.valueOf(res),
   1.200 +            new byte[] { (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x10, (byte)0xfe, (byte)0xfd, (byte)0x00, (byte)0x01 },
   1.201 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x54 }
   1.202 +        );
   1.203 +    }
   1.204 +
   1.205 +    @Test public void longModuloPositiveNumbersMultiDigitDenom()
   1.206 +            throws Exception {
   1.207 +        final long res = 0x7ffefc003322aabbL % 0x89ab1000L;
   1.208 +        assertExec("Modulo Positive Numbers Multi Digit Denom",
   1.209 +            Numbers.class, "modL__J_3B_3B",
   1.210 +            Double.valueOf(res),
   1.211 +            new byte[] { (byte)0x7f, (byte)0xfe, (byte)0xfc, (byte)0x00, (byte)0x33, (byte)0x22, (byte)0xaa, (byte)0xbb },
   1.212 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x89, (byte)0xab, (byte)0x10, (byte)0x00 }
   1.213 +        );
   1.214 +    }
   1.215 +
   1.216 +    @Test public void longModuloNegativeNumbersMultiDigitDenom()
   1.217 +            throws Exception {
   1.218 +        final long res = -0x7ffefc003322aabbL % -0x123489ab1001L;
   1.219 +        assertExec("Modulo Negative Numbers Multi Digit Denom",
   1.220 +            Numbers.class, "modL__J_3B_3B",
   1.221 +            Double.valueOf(res),
   1.222 +            new byte[] { (byte)0x80, (byte)0x01, (byte)0x03, (byte)0xff, (byte)0xcc, (byte)0xdd, (byte)0x55, (byte)0x45 },
   1.223 +            new byte[] { (byte)0xff, (byte)0xff, (byte)0xed, (byte)0xcb, (byte)0x76, (byte)0x54, (byte)0xef, (byte)0xff }
   1.224 +        );
   1.225 +    }
   1.226 +
   1.227 +    @Test public void longModuloMixedNumbersMultiDigitDenom()
   1.228 +            throws Exception {
   1.229 +        final long res = 0x7ffefc003322aabbL % -0x38f49b0b7574e36L;
   1.230 +        assertExec("Modulo Mixed Numbers Multi Digit Denom",
   1.231 +            Numbers.class, "modL__J_3B_3B",
   1.232 +            Double.valueOf(res),
   1.233 +            new byte[] { (byte)0x7f, (byte)0xfe, (byte)0xfc, (byte)0x00, (byte)0x33, (byte)0x22, (byte)0xaa, (byte)0xbb },
   1.234 +            new byte[] { (byte)0xfc, (byte)0x70, (byte)0xb6, (byte)0x4f, (byte)0x48, (byte)0xa8, (byte)0xb1, (byte)0xca }
   1.235 +        );
   1.236 +    }
   1.237 +
   1.238 +    @Test public void longModuloWithOverflow() throws Exception {
   1.239 +        final long res = 0x8000fffe0000L % 0x8000ffffL;
   1.240 +        assertExec("Modulo With Overflow",
   1.241 +            Numbers.class, "modL__J_3B_3B",
   1.242 +            Double.valueOf(res),
   1.243 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0xff, (byte)0xfe, (byte)0x00, (byte)0x00 },
   1.244 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0xff, (byte)0xff }
   1.245 +        );
   1.246 +    }
   1.247 +
   1.248 +    @Test public void longModuloWithCorrection() throws Exception {
   1.249 +        final long res = 0x7fff800000000000L % 0x800000000001L;
   1.250 +        assertExec("Modulo With Correction",
   1.251 +            Numbers.class, "modL__J_3B_3B",
   1.252 +            Double.valueOf(res),
   1.253 +            new byte[] { (byte)0x7f, (byte)0xff, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
   1.254 +            new byte[] { (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01 }
   1.255 +        );
   1.256 +    }
   1.257 +
   1.258      @Test public void longShiftL1() throws Exception {
   1.259          final long res = 0x00fa37d7763e0ca1l << 5;
   1.260          assertExec("Long << 5",