11/*
2- * Copyright (c) 2016, 2025 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2016, 2026 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
@@ -49,6 +49,7 @@ public static void main(String... args) {
4949 checkFiniteness ();
5050 checkMinMax ();
5151 checkArith ();
52+ checkOrderable ();
5253 checkSqrt ();
5354 checkGetExponent ();
5455 checkUlp ();
@@ -154,6 +155,15 @@ private static void checkConstants() {
154155 checkFloat16 (NaN , NaNf , "NaN" );
155156 }
156157
158+ private static void checkBoolean (Float16 op1 , Float16 op2 , boolean result , boolean expected , String operator ) {
159+ if (result != expected ) {
160+ throwRE (String .format ("Didn't get expected value for " +
161+ "%s %s %s %nexpected %b, got %b%n" ,
162+ op1 , operator , op2 ,
163+ expected , result ));
164+ }
165+ }
166+
157167 private static void checkInt (int value , int expected , String message ) {
158168 if (value != expected ) {
159169 throwRE (String .format ("Didn't get expected value for %s;%nexpected %d, got %d" ,
@@ -185,12 +195,18 @@ private static void checkNegate() {
185195
186196 for (var testCase : testCases ) {
187197 float arg = testCase [0 ];
198+ Float16 argF16 = valueOfExact (arg );
188199 float expected = testCase [1 ];
189200 Float16 result = negate (valueOfExact (arg ));
201+ Float16 resultOp = -argF16 ;
190202
191203 if (Float .compare (expected , result .floatValue ()) != 0 ) {
192204 checkFloat16 (result , expected , "negate(" + arg + ")" );
193205 }
206+
207+ if (Float .compare (expected , resultOp .floatValue ()) != 0 ) {
208+ checkFloat16 (result , expected , "negate(" + arg + ")" );
209+ }
194210 }
195211
196212 return ;
@@ -314,7 +330,8 @@ private static void checkMinMax() {
314330
315331 /*
316332 * Cursory checks to make sure correct operation is being called
317- * with arguments in proper order.
333+ * with arguments in proper order for both two-argument methods
334+ * and binary operators of the Numerical interface.
318335 */
319336 private static void checkArith () {
320337 float a = 1.0f ;
@@ -323,33 +340,105 @@ private static void checkArith() {
323340 float b = 2.0f ;
324341 Float16 b16 = valueOfExact (b );
325342
343+ // Addition
326344 if (add (a16 , b16 ).floatValue () != (a + b )) {
327345 throwRE ("failure with " + a16 + " + " + b16 );
328346 }
347+ if ((a16 + b16 ).floatValue () != (a + b )) { // check + operator
348+ throwRE ("failure with " + a16 + " + " + b16 );
349+ }
350+
329351 if (add (b16 , a16 ).floatValue () != (b + a )) {
330352 throwRE ("failure with " + b16 + " + " + a16 );
331353 }
354+ if ((b16 + a16 ).floatValue () != (b + a )) { // check + operator
355+ throwRE ("failure with " + b16 + " + " + a16 );
356+ }
332357
358+ // Subtraction
333359 if (subtract (a16 , b16 ).floatValue () != (a - b )) {
334360 throwRE ("failure with " + a16 + " - " + b16 );
335361 }
362+ if ((a16 - b16 ).floatValue () != (a - b )) { // check - operator
363+ throwRE ("failure with " + a16 + " - " + b16 );
364+ }
365+
336366 if (subtract (b16 , a16 ).floatValue () != (b - a )) {
337367 throwRE ("failure with " + b16 + " - " + a16 );
338368 }
369+ if ((b16 - a16 ).floatValue () != (b - a )) { // check - operator
370+ throwRE ("failure with " + b16 + " - " + a16 );
371+ }
339372
373+ // Multiplication
340374 if (multiply (a16 , b16 ).floatValue () != (a * b )) {
341375 throwRE ("failure with " + a16 + " * " + b16 );
342376 }
377+ if ((a16 * b16 ).floatValue () != (a * b )) { // check * operator
378+ throwRE ("failure with " + a16 + " * " + b16 );
379+ }
380+
343381 if (multiply (b16 , a16 ).floatValue () != (b * a )) {
344382 throwRE ("failure with " + b16 + " * " + a16 );
345383 }
384+ if ((b16 * a16 ).floatValue () != (b * a )) { // check * operator
385+ throwRE ("failure with " + b16 + " * " + a16 );
386+ }
346387
388+ // Division
347389 if (divide (a16 , b16 ).floatValue () != (a / b )) {
348390 throwRE ("failure with " + a16 + " / " + b16 );
349391 }
392+ if ((a16 / b16 ).floatValue () != (a / b )) { // check / operator
393+ throwRE ("failure with " + a16 + " / " + b16 );
394+ }
395+
350396 if (divide (b16 , a16 ).floatValue () != (b / a )) {
351397 throwRE ("failure with " + b16 + " / " + a16 );
352398 }
399+ if ((b16 / a16 ).floatValue () != (b / a )) { // check / operator
400+ throwRE ("failure with " + b16 + " / " + a16 );
401+ }
402+
403+ return ;
404+ }
405+
406+ /*
407+ * Cursory checks to make sure the ordered comparison operators
408+ * are behaving as expected.
409+ */
410+ private static void checkOrderable () {
411+ float [] testCases = {NaNf ,
412+ -InfinityF ,
413+ -1.0f ,
414+ -0.0f ,
415+ +0.0f ,
416+ 1.0f ,
417+ InfinityF };
418+
419+ for (float op1_f : testCases ) {
420+ for (float op2_f : testCases ) {
421+
422+ Float16 op1_f16 = valueOfExact (op1_f );
423+ Float16 op2_f16 = valueOfExact (op2_f );
424+
425+ checkBoolean (op1_f16 , op2_f16 ,
426+ op1_f16 < op2_f16 ,
427+ op1_f < op2_f , "<" );
428+
429+ checkBoolean (op1_f16 , op2_f16 ,
430+ op1_f16 <= op2_f16 ,
431+ op1_f <= op2_f , "<=" );
432+
433+ checkBoolean (op1_f16 , op2_f16 ,
434+ op1_f16 > op2_f16 ,
435+ op1_f > op2_f , ">" );
436+
437+ checkBoolean (op1_f16 , op2_f16 ,
438+ op1_f16 >= op2_f16 ,
439+ op1_f >= op2_f , ">=" );
440+ }
441+ }
353442 return ;
354443 }
355444
0 commit comments