1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.util.cts; 18 19 import static android.util.Half.*; 20 21 import static org.junit.Assert.assertEquals; 22 import static org.junit.Assert.assertFalse; 23 import static org.junit.Assert.assertNotEquals; 24 import static org.junit.Assert.assertTrue; 25 26 import android.util.Half; 27 28 import androidx.test.filters.SmallTest; 29 import androidx.test.runner.AndroidJUnit4; 30 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 34 @SmallTest 35 @RunWith(AndroidJUnit4.class) 36 public class HalfTest { assertShortEquals(short a, short b)37 private static void assertShortEquals(short a, short b) { 38 assertEquals((long) (a & 0xffff), (long) (b & 0xffff)); 39 } 40 assertShortEquals(int a, short b)41 private static void assertShortEquals(int a, short b) { 42 assertEquals((long) (a & 0xffff), (long) (b & 0xffff)); 43 } 44 45 @Test singleToHalf()46 public void singleToHalf() { 47 // Zeroes, NaN and infinities 48 assertShortEquals(POSITIVE_ZERO, toHalf(0.0f)); 49 assertShortEquals(NEGATIVE_ZERO, toHalf(-0.0f)); 50 assertShortEquals(NaN, toHalf(Float.NaN)); 51 assertShortEquals(POSITIVE_INFINITY, toHalf(Float.POSITIVE_INFINITY)); 52 assertShortEquals(NEGATIVE_INFINITY, toHalf(Float.NEGATIVE_INFINITY)); 53 // Known values 54 assertShortEquals(0x3c01, toHalf(1.0009765625f)); 55 assertShortEquals(0xc000, toHalf(-2.0f)); 56 assertShortEquals(0x0400, toHalf(6.10352e-5f)); 57 assertShortEquals(0x7bff, toHalf(65504.0f)); 58 assertShortEquals(0x3555, toHalf(1.0f / 3.0f)); 59 // Denormals 60 assertShortEquals(0x03ff, toHalf(6.09756e-5f)); 61 assertShortEquals(MIN_VALUE, toHalf(5.96046e-8f)); 62 assertShortEquals(0x83ff, toHalf(-6.09756e-5f)); 63 assertShortEquals(0x8001, toHalf(-5.96046e-8f)); 64 // Denormals (flushed to +/-0) 65 assertShortEquals(POSITIVE_ZERO, toHalf(5.96046e-9f)); 66 assertShortEquals(NEGATIVE_ZERO, toHalf(-5.96046e-9f)); 67 } 68 69 @Test halfToSingle()70 public void halfToSingle() { 71 // Zeroes, NaN and infinities 72 assertEquals(0.0f, toFloat(toHalf(0.0f)), 1e-6f); 73 assertEquals(-0.0f, toFloat(toHalf(-0.0f)), 1e-6f); 74 assertEquals(Float.NaN, toFloat(toHalf(Float.NaN)), 1e-6f); 75 assertEquals(Float.POSITIVE_INFINITY, toFloat(toHalf(Float.POSITIVE_INFINITY)), 1e-6f); 76 assertEquals(Float.NEGATIVE_INFINITY, toFloat(toHalf(Float.NEGATIVE_INFINITY)), 1e-6f); 77 // Known values 78 assertEquals(1.0009765625f, toFloat(toHalf(1.0009765625f)), 1e-6f); 79 assertEquals(-2.0f, toFloat(toHalf(-2.0f)), 1e-6f); 80 assertEquals(6.1035156e-5f, toFloat(toHalf(6.10352e-5f)), 1e-6f); // Inexact 81 assertEquals(65504.0f, toFloat(toHalf(65504.0f)), 1e-6f); 82 assertEquals(0.33325195f, toFloat(toHalf(1.0f / 3.0f)), 1e-6f); // Inexact 83 // Denormals (flushed to +/-0) 84 assertEquals(6.097555e-5f, toFloat(toHalf(6.09756e-5f)), 1e-6f); 85 assertEquals(5.9604645e-8f, toFloat(toHalf(5.96046e-8f)), 1e-9f); 86 assertEquals(-6.097555e-5f, toFloat(toHalf(-6.09756e-5f)), 1e-6f); 87 assertEquals(-5.9604645e-8f, toFloat(toHalf(-5.96046e-8f)), 1e-9f); 88 } 89 90 @Test hexString()91 public void hexString() { 92 assertEquals("NaN", toHexString(NaN)); 93 assertEquals("Infinity", toHexString(POSITIVE_INFINITY)); 94 assertEquals("-Infinity", toHexString(NEGATIVE_INFINITY)); 95 assertEquals("0x0.0p0", toHexString(POSITIVE_ZERO)); 96 assertEquals("-0x0.0p0", toHexString(NEGATIVE_ZERO)); 97 assertEquals("0x1.0p0", toHexString(toHalf(1.0f))); 98 assertEquals("-0x1.0p0", toHexString(toHalf(-1.0f))); 99 assertEquals("0x1.0p1", toHexString(toHalf(2.0f))); 100 assertEquals("0x1.0p8", toHexString(toHalf(256.0f))); 101 assertEquals("0x1.0p-1", toHexString(toHalf(0.5f))); 102 assertEquals("0x1.0p-2", toHexString(toHalf(0.25f))); 103 assertEquals("0x1.3ffp15", toHexString(MAX_VALUE)); 104 assertEquals("0x0.1p-14", toHexString(MIN_VALUE)); 105 assertEquals("0x1.0p-14", toHexString(MIN_NORMAL)); 106 assertEquals("-0x1.3ffp15", toHexString(LOWEST_VALUE)); 107 } 108 109 @Test string()110 public void string() { 111 assertEquals("NaN", Half.toString(NaN)); 112 assertEquals("Infinity", Half.toString(POSITIVE_INFINITY)); 113 assertEquals("-Infinity", Half.toString(NEGATIVE_INFINITY)); 114 assertEquals("0.0", Half.toString(POSITIVE_ZERO)); 115 assertEquals("-0.0", Half.toString(NEGATIVE_ZERO)); 116 assertEquals("1.0", Half.toString(toHalf(1.0f))); 117 assertEquals("-1.0", Half.toString(toHalf(-1.0f))); 118 assertEquals("2.0", Half.toString(toHalf(2.0f))); 119 assertEquals("256.0", Half.toString(toHalf(256.0f))); 120 assertEquals("0.5", Half.toString(toHalf(0.5f))); 121 assertEquals("0.25", Half.toString(toHalf(0.25f))); 122 assertEquals("65504.0", Half.toString(MAX_VALUE)); 123 assertEquals("5.9604645E-8", Half.toString(MIN_VALUE)); 124 assertEquals("6.1035156E-5", Half.toString(MIN_NORMAL)); 125 assertEquals("-65504.0", Half.toString(LOWEST_VALUE)); 126 } 127 128 @Test exponent()129 public void exponent() { 130 assertEquals(16, getExponent(POSITIVE_INFINITY)); 131 assertEquals(16, getExponent(NEGATIVE_INFINITY)); 132 assertEquals(16, getExponent(NaN)); 133 assertEquals(-15, getExponent(POSITIVE_ZERO)); 134 assertEquals(-15, getExponent(NEGATIVE_ZERO)); 135 assertEquals(0, getExponent(toHalf(1.0f))); 136 assertEquals(-4, getExponent(toHalf(0.1f))); 137 assertEquals(-10, getExponent(toHalf(0.001f))); 138 assertEquals(7, getExponent(toHalf(128.8f))); 139 } 140 141 @Test significand()142 public void significand() { 143 assertEquals(0, getSignificand(POSITIVE_INFINITY)); 144 assertEquals(0, getSignificand(NEGATIVE_INFINITY)); 145 assertEquals(512, getSignificand(NaN)); 146 assertEquals(0, getSignificand(POSITIVE_ZERO)); 147 assertEquals(0, getSignificand(NEGATIVE_ZERO)); 148 assertEquals(614, getSignificand(toHalf(0.1f))); 149 assertEquals(25, getSignificand(toHalf(0.001f))); 150 assertEquals(6, getSignificand(toHalf(128.8f))); 151 } 152 153 @Test sign()154 public void sign() { 155 assertEquals(1, getSign(POSITIVE_INFINITY)); 156 assertEquals(-1, getSign(NEGATIVE_INFINITY)); 157 assertEquals(1, getSign(POSITIVE_ZERO)); 158 assertEquals(-1, getSign(NEGATIVE_ZERO)); 159 assertEquals(1, getSign(NaN)); 160 assertEquals(1, getSign(toHalf(12.4f))); 161 assertEquals(-1, getSign(toHalf(-12.4f))); 162 } 163 164 @Test isInfinite()165 public void isInfinite() { 166 assertTrue(Half.isInfinite(POSITIVE_INFINITY)); 167 assertTrue(Half.isInfinite(NEGATIVE_INFINITY)); 168 assertFalse(Half.isInfinite(POSITIVE_ZERO)); 169 assertFalse(Half.isInfinite(NEGATIVE_ZERO)); 170 assertFalse(Half.isInfinite(NaN)); 171 assertFalse(Half.isInfinite(MAX_VALUE)); 172 assertFalse(Half.isInfinite(LOWEST_VALUE)); 173 assertFalse(Half.isInfinite(toHalf(-128.3f))); 174 assertFalse(Half.isInfinite(toHalf(128.3f))); 175 } 176 177 @Test isNaN()178 public void isNaN() { 179 assertFalse(Half.isNaN(POSITIVE_INFINITY)); 180 assertFalse(Half.isNaN(NEGATIVE_INFINITY)); 181 assertFalse(Half.isNaN(POSITIVE_ZERO)); 182 assertFalse(Half.isNaN(NEGATIVE_ZERO)); 183 assertTrue(Half.isNaN(NaN)); 184 assertTrue(Half.isNaN((short) 0x7c01)); 185 assertTrue(Half.isNaN((short) 0x7c18)); 186 assertTrue(Half.isNaN((short) 0xfc01)); 187 assertTrue(Half.isNaN((short) 0xfc98)); 188 assertFalse(Half.isNaN(MAX_VALUE)); 189 assertFalse(Half.isNaN(LOWEST_VALUE)); 190 assertFalse(Half.isNaN(toHalf(-128.3f))); 191 assertFalse(Half.isNaN(toHalf(128.3f))); 192 } 193 194 @Test isNormalized()195 public void isNormalized() { 196 assertFalse(Half.isNormalized(POSITIVE_INFINITY)); 197 assertFalse(Half.isNormalized(NEGATIVE_INFINITY)); 198 assertFalse(Half.isNormalized(POSITIVE_ZERO)); 199 assertFalse(Half.isNormalized(NEGATIVE_ZERO)); 200 assertFalse(Half.isNormalized(NaN)); 201 assertTrue(Half.isNormalized(MAX_VALUE)); 202 assertTrue(Half.isNormalized(MIN_NORMAL)); 203 assertTrue(Half.isNormalized(LOWEST_VALUE)); 204 assertTrue(Half.isNormalized(toHalf(-128.3f))); 205 assertTrue(Half.isNormalized(toHalf(128.3f))); 206 assertTrue(Half.isNormalized(toHalf(0.3456f))); 207 assertFalse(Half.isNormalized(MIN_VALUE)); 208 assertFalse(Half.isNormalized((short) 0x3ff)); 209 assertFalse(Half.isNormalized((short) 0x200)); 210 assertFalse(Half.isNormalized((short) 0x100)); 211 } 212 213 @Test abs()214 public void abs() { 215 assertShortEquals(POSITIVE_INFINITY, Half.abs(POSITIVE_INFINITY)); 216 assertShortEquals(POSITIVE_INFINITY, Half.abs(NEGATIVE_INFINITY)); 217 assertShortEquals(POSITIVE_ZERO, Half.abs(POSITIVE_ZERO)); 218 assertShortEquals(POSITIVE_ZERO, Half.abs(NEGATIVE_ZERO)); 219 assertShortEquals(NaN, Half.abs(NaN)); 220 assertShortEquals(MAX_VALUE, Half.abs(LOWEST_VALUE)); 221 assertShortEquals(toHalf(12.12345f), Half.abs(toHalf(-12.12345f))); 222 assertShortEquals(toHalf(12.12345f), Half.abs(toHalf( 12.12345f))); 223 } 224 225 @Test ceil()226 public void ceil() { 227 assertShortEquals(POSITIVE_INFINITY, Half.ceil(POSITIVE_INFINITY)); 228 assertShortEquals(NEGATIVE_INFINITY, Half.ceil(NEGATIVE_INFINITY)); 229 assertShortEquals(POSITIVE_ZERO, Half.ceil(POSITIVE_ZERO)); 230 assertShortEquals(NEGATIVE_ZERO, Half.ceil(NEGATIVE_ZERO)); 231 assertShortEquals(NaN, Half.ceil(NaN)); 232 assertShortEquals(LOWEST_VALUE, Half.ceil(LOWEST_VALUE)); 233 assertEquals(1.0f, toFloat(Half.ceil(MIN_NORMAL)), 1e-6f); 234 assertEquals(1.0f, toFloat(Half.ceil((short) 0x3ff)), 1e-6f); 235 assertEquals(1.0f, toFloat(Half.ceil(toHalf(0.2f))), 1e-6f); 236 assertShortEquals(NEGATIVE_ZERO, Half.ceil(toHalf(-0.2f))); 237 assertEquals(1.0f, toFloat(Half.ceil(toHalf(0.7f))), 1e-6f); 238 assertShortEquals(NEGATIVE_ZERO, Half.ceil(toHalf(-0.7f))); 239 assertEquals(125.0f, toFloat(Half.ceil(toHalf(124.7f))), 1e-6f); 240 assertEquals(-124.0f, toFloat(Half.ceil(toHalf(-124.7f))), 1e-6f); 241 assertEquals(125.0f, toFloat(Half.ceil(toHalf(124.2f))), 1e-6f); 242 assertEquals(-124.0f, toFloat(Half.ceil(toHalf(-124.2f))), 1e-6f); 243 } 244 245 @Test copySign()246 public void copySign() { 247 assertShortEquals(toHalf(7.5f), Half.copySign(toHalf(-7.5f), POSITIVE_INFINITY)); 248 assertShortEquals(toHalf(7.5f), Half.copySign(toHalf(-7.5f), POSITIVE_ZERO)); 249 assertShortEquals(toHalf(-7.5f), Half.copySign(toHalf(7.5f), NEGATIVE_INFINITY)); 250 assertShortEquals(toHalf(-7.5f), Half.copySign(toHalf(7.5f), NEGATIVE_ZERO)); 251 assertShortEquals(toHalf(7.5f), Half.copySign(toHalf(7.5f), NaN)); 252 assertShortEquals(toHalf(7.5f), Half.copySign(toHalf(7.5f), toHalf(12.4f))); 253 assertShortEquals(toHalf(-7.5f), Half.copySign(toHalf(7.5f), toHalf(-12.4f))); 254 } 255 256 @Test equals()257 public void equals() { 258 assertTrue(Half.equals(POSITIVE_INFINITY, POSITIVE_INFINITY)); 259 assertTrue(Half.equals(NEGATIVE_INFINITY, NEGATIVE_INFINITY)); 260 assertTrue(Half.equals(POSITIVE_ZERO, POSITIVE_ZERO)); 261 assertTrue(Half.equals(NEGATIVE_ZERO, NEGATIVE_ZERO)); 262 assertTrue(Half.equals(POSITIVE_ZERO, NEGATIVE_ZERO)); 263 assertFalse(Half.equals(NaN, toHalf(12.4f))); 264 assertFalse(Half.equals(toHalf(12.4f), NaN)); 265 assertFalse(Half.equals(NaN, NaN)); 266 assertTrue(Half.equals(toHalf(12.4f), toHalf(12.4f))); 267 assertTrue(Half.equals(toHalf(-12.4f), toHalf(-12.4f))); 268 assertFalse(Half.equals(toHalf(12.4f), toHalf(0.7f))); 269 270 //noinspection UnnecessaryBoxing 271 assertNotEquals(Half.valueOf(0.0f), Float.valueOf(0.0f)); 272 assertEquals(Half.valueOf(NaN), Half.valueOf((short) 0x7c01)); // NaN, NaN 273 assertEquals(Half.valueOf(NaN), Half.valueOf((short) 0xfc98)); // NaN, NaN 274 275 assertEquals(Half.valueOf(POSITIVE_INFINITY), Half.valueOf(POSITIVE_INFINITY)); 276 assertEquals(Half.valueOf(NEGATIVE_INFINITY), Half.valueOf(NEGATIVE_INFINITY)); 277 assertEquals(Half.valueOf(POSITIVE_ZERO), Half.valueOf(POSITIVE_ZERO)); 278 assertEquals(Half.valueOf(NEGATIVE_ZERO), Half.valueOf(NEGATIVE_ZERO)); 279 assertNotEquals(Half.valueOf(POSITIVE_ZERO), Half.valueOf(NEGATIVE_ZERO)); 280 assertNotEquals(Half.valueOf(NaN), Half.valueOf(12.4f)); 281 assertNotEquals(Half.valueOf(12.4f), Half.valueOf(NaN)); 282 assertEquals(Half.valueOf(12.4f), Half.valueOf(12.4f)); 283 assertEquals(Half.valueOf(-12.4f), Half.valueOf(-12.4f)); 284 assertNotEquals(Half.valueOf(12.4f), Half.valueOf(0.7f)); 285 } 286 287 @Test floor()288 public void floor() { 289 assertShortEquals(POSITIVE_INFINITY, Half.floor(POSITIVE_INFINITY)); 290 assertShortEquals(NEGATIVE_INFINITY, Half.floor(NEGATIVE_INFINITY)); 291 assertShortEquals(POSITIVE_ZERO, Half.floor(POSITIVE_ZERO)); 292 assertShortEquals(NEGATIVE_ZERO, Half.floor(NEGATIVE_ZERO)); 293 assertShortEquals(NaN, Half.floor(NaN)); 294 assertShortEquals(LOWEST_VALUE, Half.floor(LOWEST_VALUE)); 295 assertShortEquals(POSITIVE_ZERO, Half.floor(MIN_NORMAL)); 296 assertShortEquals(POSITIVE_ZERO, Half.floor((short) 0x3ff)); 297 assertShortEquals(POSITIVE_ZERO, Half.floor(toHalf(0.2f))); 298 assertEquals(-1.0f, toFloat(Half.floor(toHalf(-0.2f))), 1e-6f); 299 assertEquals(-1.0f, toFloat(Half.floor(toHalf(-0.7f))), 1e-6f); 300 assertShortEquals(POSITIVE_ZERO, Half.floor(toHalf(0.7f))); 301 assertEquals(124.0f, toFloat(Half.floor(toHalf(124.7f))), 1e-6f); 302 assertEquals(-125.0f, toFloat(Half.floor(toHalf(-124.7f))), 1e-6f); 303 assertEquals(124.0f, toFloat(Half.floor(toHalf(124.2f))), 1e-6f); 304 assertEquals(-125.0f, toFloat(Half.floor(toHalf(-124.2f))), 1e-6f); 305 } 306 307 @Test round()308 public void round() { 309 assertShortEquals(POSITIVE_INFINITY, Half.round(POSITIVE_INFINITY)); 310 assertShortEquals(NEGATIVE_INFINITY, Half.round(NEGATIVE_INFINITY)); 311 assertShortEquals(POSITIVE_ZERO, Half.round(POSITIVE_ZERO)); 312 assertShortEquals(NEGATIVE_ZERO, Half.round(NEGATIVE_ZERO)); 313 assertShortEquals(NaN, Half.round(NaN)); 314 assertShortEquals(LOWEST_VALUE, Half.round(LOWEST_VALUE)); 315 assertShortEquals(POSITIVE_ZERO, Half.round(MIN_VALUE)); 316 assertShortEquals(POSITIVE_ZERO, Half.round((short) 0x200)); 317 assertShortEquals(POSITIVE_ZERO, Half.round((short) 0x3ff)); 318 assertShortEquals(POSITIVE_ZERO, Half.round(toHalf(0.2f))); 319 assertShortEquals(NEGATIVE_ZERO, Half.round(toHalf(-0.2f))); 320 assertEquals(1.0f, toFloat(Half.round(toHalf(0.7f))), 1e-6f); 321 assertEquals(-1.0f, toFloat(Half.round(toHalf(-0.7f))), 1e-6f); 322 assertEquals(1.0f, toFloat(Half.round(toHalf(0.5f))), 1e-6f); 323 assertEquals(-1.0f, toFloat(Half.round(toHalf(-0.5f))), 1e-6f); 324 assertEquals(125.0f, toFloat(Half.round(toHalf(124.7f))), 1e-6f); 325 assertEquals(-125.0f, toFloat(Half.round(toHalf(-124.7f))), 1e-6f); 326 assertEquals(124.0f, toFloat(Half.round(toHalf(124.2f))), 1e-6f); 327 assertEquals(-124.0f, toFloat(Half.round(toHalf(-124.2f))), 1e-6f); 328 } 329 330 @Test trunc()331 public void trunc() { 332 assertShortEquals(POSITIVE_INFINITY, Half.trunc(POSITIVE_INFINITY)); 333 assertShortEquals(NEGATIVE_INFINITY, Half.trunc(NEGATIVE_INFINITY)); 334 assertShortEquals(POSITIVE_ZERO, Half.trunc(POSITIVE_ZERO)); 335 assertShortEquals(NEGATIVE_ZERO, Half.trunc(NEGATIVE_ZERO)); 336 assertShortEquals(NaN, Half.trunc(NaN)); 337 assertShortEquals(LOWEST_VALUE, Half.trunc(LOWEST_VALUE)); 338 assertShortEquals(POSITIVE_ZERO, Half.trunc(toHalf(0.2f))); 339 assertShortEquals(NEGATIVE_ZERO, Half.trunc(toHalf(-0.2f))); 340 assertEquals(0.0f, toFloat(Half.trunc(toHalf(0.7f))), 1e-6f); 341 assertEquals(-0.0f, toFloat(Half.trunc(toHalf(-0.7f))), 1e-6f); 342 assertEquals(124.0f, toFloat(Half.trunc(toHalf(124.7f))), 1e-6f); 343 assertEquals(-124.0f, toFloat(Half.trunc(toHalf(-124.7f))), 1e-6f); 344 assertEquals(124.0f, toFloat(Half.trunc(toHalf(124.2f))), 1e-6f); 345 assertEquals(-124.0f, toFloat(Half.trunc(toHalf(-124.2f))), 1e-6f); 346 } 347 348 @Test less()349 public void less() { 350 assertTrue(Half.less(NEGATIVE_INFINITY, POSITIVE_INFINITY)); 351 assertTrue(Half.less(MAX_VALUE, POSITIVE_INFINITY)); 352 assertFalse(Half.less(POSITIVE_INFINITY, MAX_VALUE)); 353 assertFalse(Half.less(LOWEST_VALUE, NEGATIVE_INFINITY)); 354 assertTrue(Half.less(NEGATIVE_INFINITY, LOWEST_VALUE)); 355 assertFalse(Half.less(POSITIVE_ZERO, NEGATIVE_ZERO)); 356 assertFalse(Half.less(NEGATIVE_ZERO, POSITIVE_ZERO)); 357 assertFalse(Half.less(NaN, toHalf(12.3f))); 358 assertFalse(Half.less(toHalf(12.3f), NaN)); 359 assertTrue(Half.less(MIN_VALUE, MIN_NORMAL)); 360 assertFalse(Half.less(MIN_NORMAL, MIN_VALUE)); 361 assertTrue(Half.less(toHalf(12.3f), toHalf(12.4f))); 362 assertFalse(Half.less(toHalf(12.4f), toHalf(12.3f))); 363 assertFalse(Half.less(toHalf(-12.3f), toHalf(-12.4f))); 364 assertTrue(Half.less(toHalf(-12.4f), toHalf(-12.3f))); 365 assertTrue(Half.less(MIN_VALUE, (short) 0x3ff)); 366 } 367 368 @Test lessEquals()369 public void lessEquals() { 370 assertTrue(Half.less(NEGATIVE_INFINITY, POSITIVE_INFINITY)); 371 assertTrue(Half.lessEquals(MAX_VALUE, POSITIVE_INFINITY)); 372 assertFalse(Half.lessEquals(POSITIVE_INFINITY, MAX_VALUE)); 373 assertFalse(Half.lessEquals(LOWEST_VALUE, NEGATIVE_INFINITY)); 374 assertTrue(Half.lessEquals(NEGATIVE_INFINITY, LOWEST_VALUE)); 375 assertTrue(Half.lessEquals(POSITIVE_ZERO, NEGATIVE_ZERO)); 376 assertTrue(Half.lessEquals(NEGATIVE_ZERO, POSITIVE_ZERO)); 377 assertFalse(Half.lessEquals(NaN, toHalf(12.3f))); 378 assertFalse(Half.lessEquals(toHalf(12.3f), NaN)); 379 assertTrue(Half.lessEquals(MIN_VALUE, MIN_NORMAL)); 380 assertFalse(Half.lessEquals(MIN_NORMAL, MIN_VALUE)); 381 assertTrue(Half.lessEquals(toHalf(12.3f), toHalf(12.4f))); 382 assertFalse(Half.lessEquals(toHalf(12.4f), toHalf(12.3f))); 383 assertFalse(Half.lessEquals(toHalf(-12.3f), toHalf(-12.4f))); 384 assertTrue(Half.lessEquals(toHalf(-12.4f), toHalf(-12.3f))); 385 assertTrue(Half.less(MIN_VALUE, (short) 0x3ff)); 386 assertTrue(Half.lessEquals(NEGATIVE_INFINITY, NEGATIVE_INFINITY)); 387 assertTrue(Half.lessEquals(POSITIVE_INFINITY, POSITIVE_INFINITY)); 388 assertTrue(Half.lessEquals(toHalf(12.12356f), toHalf(12.12356f))); 389 assertTrue(Half.lessEquals(toHalf(-12.12356f), toHalf(-12.12356f))); 390 } 391 392 @Test greater()393 public void greater() { 394 assertTrue(Half.greater(POSITIVE_INFINITY, NEGATIVE_INFINITY)); 395 assertTrue(Half.greater(POSITIVE_INFINITY, MAX_VALUE)); 396 assertFalse(Half.greater(MAX_VALUE, POSITIVE_INFINITY)); 397 assertFalse(Half.greater(NEGATIVE_INFINITY, LOWEST_VALUE)); 398 assertTrue(Half.greater(LOWEST_VALUE, NEGATIVE_INFINITY)); 399 assertFalse(Half.greater(NEGATIVE_ZERO, POSITIVE_ZERO)); 400 assertFalse(Half.greater(POSITIVE_ZERO, NEGATIVE_ZERO)); 401 assertFalse(Half.greater(toHalf(12.3f), NaN)); 402 assertFalse(Half.greater(NaN, toHalf(12.3f))); 403 assertTrue(Half.greater(MIN_NORMAL, MIN_VALUE)); 404 assertFalse(Half.greater(MIN_VALUE, MIN_NORMAL)); 405 assertTrue(Half.greater(toHalf(12.4f), toHalf(12.3f))); 406 assertFalse(Half.greater(toHalf(12.3f), toHalf(12.4f))); 407 assertFalse(Half.greater(toHalf(-12.4f), toHalf(-12.3f))); 408 assertTrue(Half.greater(toHalf(-12.3f), toHalf(-12.4f))); 409 assertTrue(Half.greater((short) 0x3ff, MIN_VALUE)); 410 } 411 412 @Test greaterEquals()413 public void greaterEquals() { 414 assertTrue(Half.greaterEquals(POSITIVE_INFINITY, NEGATIVE_INFINITY)); 415 assertTrue(Half.greaterEquals(POSITIVE_INFINITY, MAX_VALUE)); 416 assertFalse(Half.greaterEquals(MAX_VALUE, POSITIVE_INFINITY)); 417 assertFalse(Half.greaterEquals(NEGATIVE_INFINITY, LOWEST_VALUE)); 418 assertTrue(Half.greaterEquals(LOWEST_VALUE, NEGATIVE_INFINITY)); 419 assertTrue(Half.greaterEquals(NEGATIVE_ZERO, POSITIVE_ZERO)); 420 assertTrue(Half.greaterEquals(POSITIVE_ZERO, NEGATIVE_ZERO)); 421 assertFalse(Half.greaterEquals(toHalf(12.3f), NaN)); 422 assertFalse(Half.greaterEquals(NaN, toHalf(12.3f))); 423 assertTrue(Half.greaterEquals(MIN_NORMAL, MIN_VALUE)); 424 assertFalse(Half.greaterEquals(MIN_VALUE, MIN_NORMAL)); 425 assertTrue(Half.greaterEquals(toHalf(12.4f), toHalf(12.3f))); 426 assertFalse(Half.greaterEquals(toHalf(12.3f), toHalf(12.4f))); 427 assertFalse(Half.greaterEquals(toHalf(-12.4f), toHalf(-12.3f))); 428 assertTrue(Half.greaterEquals(toHalf(-12.3f), toHalf(-12.4f))); 429 assertTrue(Half.greater((short) 0x3ff, MIN_VALUE)); 430 assertTrue(Half.lessEquals(NEGATIVE_INFINITY, NEGATIVE_INFINITY)); 431 assertTrue(Half.lessEquals(POSITIVE_INFINITY, POSITIVE_INFINITY)); 432 assertTrue(Half.lessEquals(toHalf(12.12356f), toHalf(12.12356f))); 433 assertTrue(Half.lessEquals(toHalf(-12.12356f), toHalf(-12.12356f))); 434 } 435 436 @Test min()437 public void min() { 438 assertShortEquals(NEGATIVE_INFINITY, Half.min(POSITIVE_INFINITY, NEGATIVE_INFINITY)); 439 assertShortEquals(NEGATIVE_ZERO, Half.min(POSITIVE_ZERO, NEGATIVE_ZERO)); 440 assertShortEquals(NaN, Half.min(NaN, LOWEST_VALUE)); 441 assertShortEquals(NaN, Half.min(LOWEST_VALUE, NaN)); 442 assertShortEquals(NEGATIVE_INFINITY, Half.min(NEGATIVE_INFINITY, LOWEST_VALUE)); 443 assertShortEquals(MAX_VALUE, Half.min(POSITIVE_INFINITY, MAX_VALUE)); 444 assertShortEquals(MIN_VALUE, Half.min(MIN_VALUE, MIN_NORMAL)); 445 assertShortEquals(POSITIVE_ZERO, Half.min(MIN_VALUE, POSITIVE_ZERO)); 446 assertShortEquals(POSITIVE_ZERO, Half.min(MIN_NORMAL, POSITIVE_ZERO)); 447 assertShortEquals(toHalf(-3.456f), Half.min(toHalf(-3.456f), toHalf(-3.453f))); 448 assertShortEquals(toHalf(3.453f), Half.min(toHalf(3.456f), toHalf(3.453f))); 449 } 450 451 @Test max()452 public void max() { 453 assertShortEquals(POSITIVE_INFINITY, Half.max(POSITIVE_INFINITY, NEGATIVE_INFINITY)); 454 assertShortEquals(POSITIVE_ZERO, Half.max(POSITIVE_ZERO, NEGATIVE_ZERO)); 455 assertShortEquals(NaN, Half.max(NaN, MAX_VALUE)); 456 assertShortEquals(NaN, Half.max(MAX_VALUE, NaN)); 457 assertShortEquals(LOWEST_VALUE, Half.max(NEGATIVE_INFINITY, LOWEST_VALUE)); 458 assertShortEquals(POSITIVE_INFINITY, Half.max(POSITIVE_INFINITY, MAX_VALUE)); 459 assertShortEquals(MIN_NORMAL, Half.max(MIN_VALUE, MIN_NORMAL)); 460 assertShortEquals(MIN_VALUE, Half.max(MIN_VALUE, POSITIVE_ZERO)); 461 assertShortEquals(MIN_NORMAL, Half.max(MIN_NORMAL, POSITIVE_ZERO)); 462 assertShortEquals(toHalf(-3.453f), Half.max(toHalf(-3.456f), toHalf(-3.453f))); 463 assertShortEquals(toHalf(3.456f), Half.max(toHalf(3.456f), toHalf(3.453f))); 464 } 465 466 @Test numberInterface()467 public void numberInterface() { 468 assertEquals(12, Half.valueOf(12.57f).byteValue()); 469 assertEquals(12, Half.valueOf(12.57f).shortValue()); 470 assertEquals(12, Half.valueOf(12.57f).intValue()); 471 assertEquals(12, Half.valueOf(12.57f).longValue()); 472 assertEquals(12.57f, Half.valueOf(12.57f).floatValue(), 1e-3f); 473 assertEquals(12.57, Half.valueOf(12.57f).doubleValue(), 1e-3); 474 475 assertEquals(-12, Half.valueOf(-12.57f).byteValue()); 476 assertEquals(-12, Half.valueOf(-12.57f).shortValue()); 477 assertEquals(-12, Half.valueOf(-12.57f).intValue()); 478 assertEquals(-12, Half.valueOf(-12.57f).longValue()); 479 assertEquals(-12.57f, Half.valueOf(-12.57f).floatValue(), 1e-3f); 480 assertEquals(-12.57, Half.valueOf(-12.57f).doubleValue(), 1e-3); 481 482 assertEquals(0, Half.valueOf(POSITIVE_ZERO).byteValue()); 483 assertEquals(0, Half.valueOf(POSITIVE_ZERO).shortValue()); 484 assertEquals(0, Half.valueOf(POSITIVE_ZERO).intValue()); 485 assertEquals(0, Half.valueOf(POSITIVE_ZERO).longValue()); 486 assertTrue(+0.0f == Half.valueOf(POSITIVE_ZERO).floatValue()); 487 assertTrue(+0.0 == Half.valueOf(POSITIVE_ZERO).doubleValue()); 488 489 assertEquals(0, Half.valueOf(NEGATIVE_ZERO).byteValue()); 490 assertEquals(0, Half.valueOf(NEGATIVE_ZERO).shortValue()); 491 assertEquals(0, Half.valueOf(NEGATIVE_ZERO).intValue()); 492 assertEquals(0, Half.valueOf(NEGATIVE_ZERO).longValue()); 493 assertTrue(-0.0f == Half.valueOf(NEGATIVE_ZERO).floatValue()); 494 assertTrue(-0.0 == Half.valueOf(NEGATIVE_ZERO).doubleValue()); 495 496 assertEquals(-1, Half.valueOf(POSITIVE_INFINITY).byteValue()); 497 assertEquals(-1, Half.valueOf(POSITIVE_INFINITY).shortValue()); 498 assertEquals(Integer.MAX_VALUE, Half.valueOf(POSITIVE_INFINITY).intValue()); 499 assertEquals(Long.MAX_VALUE, Half.valueOf(POSITIVE_INFINITY).longValue()); 500 assertTrue(Float.POSITIVE_INFINITY == Half.valueOf(POSITIVE_INFINITY).floatValue()); 501 assertTrue(Double.POSITIVE_INFINITY == Half.valueOf(POSITIVE_INFINITY).doubleValue()); 502 503 assertEquals(0, Half.valueOf(NEGATIVE_INFINITY).byteValue()); 504 assertEquals(0, Half.valueOf(NEGATIVE_INFINITY).shortValue()); 505 assertEquals(Integer.MIN_VALUE, Half.valueOf(NEGATIVE_INFINITY).intValue()); 506 assertEquals(Long.MIN_VALUE, Half.valueOf(NEGATIVE_INFINITY).longValue()); 507 assertTrue(Float.NEGATIVE_INFINITY == Half.valueOf(NEGATIVE_INFINITY).floatValue()); 508 assertTrue(Double.NEGATIVE_INFINITY == Half.valueOf(NEGATIVE_INFINITY).doubleValue()); 509 510 assertEquals(0, Half.valueOf(NaN).byteValue()); 511 assertEquals(0, Half.valueOf(NaN).shortValue()); 512 assertEquals(0, Half.valueOf(NaN).intValue()); 513 assertEquals(0, Half.valueOf(NaN).longValue()); 514 assertEquals(Float.floatToRawIntBits(Float.NaN), 515 Float.floatToRawIntBits(Half.valueOf(NaN).floatValue())); 516 assertEquals(Double.doubleToRawLongBits(Double.NaN), 517 Double.doubleToRawLongBits(Half.valueOf(NaN).doubleValue())); 518 } 519 520 @SuppressWarnings("PointlessBitwiseExpression") 521 @Test bits()522 public void bits() { 523 assertEquals(POSITIVE_INFINITY & 0xffff, halfToRawIntBits(POSITIVE_INFINITY)); 524 assertEquals(NEGATIVE_INFINITY & 0xffff, halfToRawIntBits(NEGATIVE_INFINITY)); 525 assertEquals(POSITIVE_ZERO & 0xffff, halfToRawIntBits(POSITIVE_ZERO)); 526 assertEquals(NEGATIVE_ZERO & 0xffff, halfToRawIntBits(NEGATIVE_ZERO)); 527 assertEquals(NaN & 0xffff, halfToRawIntBits(NaN)); 528 assertEquals(0xfc98, halfToRawIntBits((short) 0xfc98)); // NaN 529 assertEquals(toHalf(12.462f) & 0xffff, halfToRawIntBits(toHalf(12.462f))); 530 assertEquals(toHalf(-12.462f) & 0xffff, halfToRawIntBits(toHalf(-12.462f))); 531 532 assertEquals(POSITIVE_INFINITY & 0xffff, halfToIntBits(POSITIVE_INFINITY)); 533 assertEquals(NEGATIVE_INFINITY & 0xffff, halfToIntBits(NEGATIVE_INFINITY)); 534 assertEquals(POSITIVE_ZERO & 0xffff, halfToIntBits(POSITIVE_ZERO)); 535 assertEquals(NEGATIVE_ZERO & 0xffff, halfToIntBits(NEGATIVE_ZERO)); 536 assertEquals(NaN & 0xffff, halfToIntBits(NaN)); 537 assertEquals(NaN & 0xffff, halfToIntBits((short) 0xfc98)); // NaN 538 assertEquals(toHalf(12.462f) & 0xffff, halfToIntBits(toHalf(12.462f))); 539 assertEquals(toHalf(-12.462f) & 0xffff, halfToIntBits(toHalf(-12.462f))); 540 541 assertShortEquals(POSITIVE_INFINITY, intBitsToHalf(halfToIntBits(POSITIVE_INFINITY))); 542 assertShortEquals(NEGATIVE_INFINITY, intBitsToHalf(halfToIntBits(NEGATIVE_INFINITY))); 543 assertShortEquals(POSITIVE_ZERO, intBitsToHalf(halfToIntBits(POSITIVE_ZERO))); 544 assertShortEquals(NEGATIVE_ZERO, intBitsToHalf(halfToIntBits(NEGATIVE_ZERO))); 545 assertShortEquals(NaN, intBitsToHalf(halfToIntBits(NaN))); 546 assertShortEquals(NaN, intBitsToHalf(halfToIntBits((short) 0xfc98))); 547 assertShortEquals(toHalf(12.462f), intBitsToHalf(halfToIntBits(toHalf(12.462f)))); 548 assertShortEquals(toHalf(-12.462f), intBitsToHalf(halfToIntBits(toHalf(-12.462f)))); 549 550 assertShortEquals(POSITIVE_INFINITY, halfToShortBits(POSITIVE_INFINITY)); 551 assertShortEquals(NEGATIVE_INFINITY, halfToShortBits(NEGATIVE_INFINITY)); 552 assertShortEquals(POSITIVE_ZERO, halfToShortBits(POSITIVE_ZERO)); 553 assertShortEquals(NEGATIVE_ZERO, halfToShortBits(NEGATIVE_ZERO)); 554 assertShortEquals(NaN, halfToShortBits(NaN)); 555 assertShortEquals(NaN, halfToShortBits((short) 0xfc98)); // NaN 556 assertShortEquals(toHalf(12.462f), halfToShortBits(toHalf(12.462f))); 557 assertShortEquals(toHalf(-12.462f), halfToShortBits(toHalf(-12.462f))); 558 } 559 560 @Test hashCodeGeneration()561 public void hashCodeGeneration() { 562 assertNotEquals(Half.hashCode(POSITIVE_INFINITY), Half.hashCode(NEGATIVE_INFINITY)); 563 assertNotEquals(Half.hashCode(POSITIVE_ZERO), Half.hashCode(NEGATIVE_ZERO)); 564 assertNotEquals(Half.hashCode(toHalf(1.999f)), Half.hashCode(toHalf(1.998f))); 565 assertEquals(Half.hashCode(NaN), Half.hashCode((short) 0x7c01)); 566 assertEquals(Half.hashCode(NaN), Half.hashCode((short) 0xfc98)); 567 568 assertEquals(Half.hashCode(POSITIVE_INFINITY), Half.valueOf(POSITIVE_INFINITY).hashCode()); 569 assertEquals(Half.hashCode(NEGATIVE_INFINITY), Half.valueOf(NEGATIVE_INFINITY).hashCode()); 570 assertEquals(Half.hashCode(POSITIVE_ZERO), Half.valueOf(POSITIVE_ZERO).hashCode()); 571 assertEquals(Half.hashCode(NEGATIVE_ZERO), Half.valueOf(NEGATIVE_ZERO).hashCode()); 572 assertEquals(Half.hashCode(NaN), Half.valueOf(NaN).hashCode()); 573 assertEquals(Half.hashCode((short) 0xfc98), Half.valueOf((short) 0xfc98).hashCode()); 574 assertEquals(Half.hashCode(toHalf(1.999f)), Half.valueOf(1.999f).hashCode()); 575 } 576 577 @Test constructors()578 public void constructors() { 579 assertEquals(POSITIVE_INFINITY, new Half(POSITIVE_INFINITY).halfValue()); 580 assertEquals(NEGATIVE_INFINITY, new Half(NEGATIVE_INFINITY).halfValue()); 581 assertEquals(POSITIVE_ZERO, new Half(POSITIVE_ZERO).halfValue()); 582 assertEquals(NEGATIVE_ZERO, new Half(NEGATIVE_ZERO).halfValue()); 583 assertEquals(NaN, new Half(NaN).halfValue()); 584 assertEquals(toHalf(12.57f), new Half(toHalf(12.57f)).halfValue()); 585 assertEquals(toHalf(-12.57f), new Half(toHalf(-12.57f)).halfValue()); 586 587 assertEquals(POSITIVE_INFINITY, new Half(Float.POSITIVE_INFINITY).halfValue()); 588 assertEquals(NEGATIVE_INFINITY, new Half(Float.NEGATIVE_INFINITY).halfValue()); 589 assertEquals(POSITIVE_ZERO, new Half(0.0f).halfValue()); 590 assertEquals(NEGATIVE_ZERO, new Half(-0.0f).halfValue()); 591 assertEquals(NaN, new Half(Float.NaN).halfValue()); 592 assertEquals(toHalf(12.57f), new Half(12.57f).halfValue()); 593 assertEquals(toHalf(-12.57f), new Half(-12.57f).halfValue()); 594 595 assertEquals(POSITIVE_INFINITY, new Half(Double.POSITIVE_INFINITY).halfValue()); 596 assertEquals(NEGATIVE_INFINITY, new Half(Double.NEGATIVE_INFINITY).halfValue()); 597 assertEquals(POSITIVE_ZERO, new Half(0.0).halfValue()); 598 assertEquals(NEGATIVE_ZERO, new Half(-0.0).halfValue()); 599 assertEquals(NaN, new Half(Double.NaN).halfValue()); 600 assertEquals(toHalf(12.57f), new Half(12.57).halfValue()); 601 assertEquals(toHalf(-12.57f), new Half(-12.57).halfValue()); 602 603 assertEquals(POSITIVE_INFINITY, new Half("+Infinity").halfValue()); 604 assertEquals(NEGATIVE_INFINITY, new Half("-Infinity").halfValue()); 605 assertEquals(POSITIVE_ZERO, new Half("0.0").halfValue()); 606 assertEquals(NEGATIVE_ZERO, new Half("-0.0").halfValue()); 607 assertEquals(NaN, new Half("NaN").halfValue()); 608 assertEquals(toHalf(12.57f), new Half("1257e-2").halfValue()); 609 assertEquals(toHalf(-12.57f), new Half("-1257e-2").halfValue()); 610 } 611 612 @Test(expected = NumberFormatException.class) constructorFailure()613 public void constructorFailure() { 614 new Half("not a number"); 615 } 616 617 @Test parse()618 public void parse() { 619 assertShortEquals(parseHalf("NaN"), NaN); 620 assertShortEquals(parseHalf("Infinity"), POSITIVE_INFINITY); 621 assertShortEquals(parseHalf("-Infinity"), NEGATIVE_INFINITY); 622 assertShortEquals(parseHalf("0.0"), POSITIVE_ZERO); 623 assertShortEquals(parseHalf("-0.0"), NEGATIVE_ZERO); 624 assertShortEquals(parseHalf("1.0"), toHalf(1.0f)); 625 assertShortEquals(parseHalf("-1.0"), toHalf(-1.0f)); 626 assertShortEquals(parseHalf("2.0"), toHalf(2.0f)); 627 assertShortEquals(parseHalf("256.0"), toHalf(256.0f)); 628 assertShortEquals(parseHalf("0.5"), toHalf(0.5f)); 629 assertShortEquals(parseHalf("0.25"), toHalf(0.25f)); 630 assertShortEquals(parseHalf("65504.0"), MAX_VALUE); 631 assertShortEquals(parseHalf("5.9604645E-8"), MIN_VALUE); 632 assertShortEquals(parseHalf("6.1035156E-5"), MIN_NORMAL); 633 assertShortEquals(parseHalf("-65504.0"), LOWEST_VALUE); 634 } 635 636 @Test(expected = NumberFormatException.class) parseFailure()637 public void parseFailure() { 638 parseHalf("not a number"); 639 } 640 641 @Test valueOf()642 public void valueOf() { 643 assertEquals(POSITIVE_INFINITY, Half.valueOf(POSITIVE_INFINITY).halfValue()); 644 assertEquals(NEGATIVE_INFINITY, Half.valueOf(NEGATIVE_INFINITY).halfValue()); 645 assertEquals(POSITIVE_ZERO, Half.valueOf(POSITIVE_ZERO).halfValue()); 646 assertEquals(NEGATIVE_ZERO, Half.valueOf(NEGATIVE_ZERO).halfValue()); 647 assertEquals(NaN, Half.valueOf(NaN).halfValue()); 648 assertEquals(toHalf(12.57f), Half.valueOf(toHalf(12.57f)).halfValue()); 649 assertEquals(toHalf(-12.57f), Half.valueOf(toHalf(-12.57f)).halfValue()); 650 651 assertEquals(POSITIVE_INFINITY, Half.valueOf(Float.POSITIVE_INFINITY).halfValue()); 652 assertEquals(NEGATIVE_INFINITY, Half.valueOf(Float.NEGATIVE_INFINITY).halfValue()); 653 assertEquals(POSITIVE_ZERO, Half.valueOf(0.0f).halfValue()); 654 assertEquals(NEGATIVE_ZERO, Half.valueOf(-0.0f).halfValue()); 655 assertEquals(NaN, Half.valueOf(Float.NaN).halfValue()); 656 assertEquals(toHalf(12.57f), Half.valueOf(12.57f).halfValue()); 657 assertEquals(toHalf(-12.57f), Half.valueOf(-12.57f).halfValue()); 658 659 assertEquals(POSITIVE_INFINITY, Half.valueOf("+Infinity").halfValue()); 660 assertEquals(NEGATIVE_INFINITY, Half.valueOf("-Infinity").halfValue()); 661 assertEquals(POSITIVE_ZERO, Half.valueOf("0.0").halfValue()); 662 assertEquals(NEGATIVE_ZERO, Half.valueOf("-0.0").halfValue()); 663 assertEquals(NaN, Half.valueOf("NaN").halfValue()); 664 assertEquals(toHalf(12.57f), Half.valueOf("1257e-2").halfValue()); 665 assertEquals(toHalf(-12.57f), Half.valueOf("-1257e-2").halfValue()); 666 } 667 668 @Test compare()669 public void compare() { 670 assertEquals(0, Half.compare(NaN, NaN)); 671 assertEquals(0, Half.compare(NaN, (short) 0xfc98)); 672 assertEquals(1, Half.compare(NaN, POSITIVE_INFINITY)); 673 assertEquals(-1, Half.compare(POSITIVE_INFINITY, NaN)); 674 675 assertEquals(0, Half.compare(POSITIVE_INFINITY, POSITIVE_INFINITY)); 676 assertEquals(0, Half.compare(NEGATIVE_INFINITY, NEGATIVE_INFINITY)); 677 assertEquals(1, Half.compare(POSITIVE_INFINITY, NEGATIVE_INFINITY)); 678 assertEquals(-1, Half.compare(NEGATIVE_INFINITY, POSITIVE_INFINITY)); 679 680 assertEquals(0, Half.compare(POSITIVE_ZERO, POSITIVE_ZERO)); 681 assertEquals(0, Half.compare(NEGATIVE_ZERO, NEGATIVE_ZERO)); 682 assertEquals(1, Half.compare(POSITIVE_ZERO, NEGATIVE_ZERO)); 683 assertEquals(-1, Half.compare(NEGATIVE_ZERO, POSITIVE_ZERO)); 684 685 assertEquals(0, Half.compare(toHalf(12.462f), toHalf(12.462f))); 686 assertEquals(0, Half.compare(toHalf(-12.462f), toHalf(-12.462f))); 687 assertEquals(1, Half.compare(toHalf(12.462f), toHalf(-12.462f))); 688 assertEquals(-1, Half.compare(toHalf(-12.462f), toHalf(12.462f))); 689 } 690 } 691