1 /*
2  * Copyright (C) 2018 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 import libcore.util.FP16;
18 
19 public class Main {
Main()20     public Main() {
21     }
22 
TestFP16ToFloatRawIntBits(short half)23     public static int TestFP16ToFloatRawIntBits(short half) {
24         float f = FP16.toFloat(half);
25         // Since in this test class we need to check the integer representing of
26         // the actual float NaN values, the floatToRawIntBits() is used instead of
27         // floatToIntBits().
28         return Float.floatToRawIntBits(f);
29     }
30 
assertEquals(short expected, short calculated)31     public static void assertEquals(short expected, short calculated) {
32         if (expected != calculated) {
33             throw new Error("Expected: " + expected + ", Calculated: " + calculated);
34         }
35     }
assertEquals(float expected, float calculated)36     public static void assertEquals(float expected, float calculated) {
37         if (expected != calculated) {
38             throw new Error("Expected: " + expected + ", Calculated: " + calculated);
39         }
40     }
assertTrue(boolean condition)41     static public void assertTrue(boolean condition) {
42         if (!condition) {
43             throw new Error("condition not true");
44         }
45     }
46 
assertFalse(boolean condition)47     static public void assertFalse(boolean condition) {
48         if (condition) {
49             throw new Error("condition not false");
50         }
51     }
52 
testHalfToFloatToHalfConversions()53     public static void testHalfToFloatToHalfConversions(){
54         // Test FP16 to float and back to Half for all possible Short values
55         for (short h = Short.MIN_VALUE; h < Short.MAX_VALUE; h++) {
56             if (FP16.isNaN(h)) {
57                 // NaN inputs are tested below.
58                 continue;
59             }
60             assertEquals(h, FP16.toHalf(FP16.toFloat(h)));
61         }
62     }
63 
testToHalf()64     public static void testToHalf(){
65         // These asserts check some known values and edge cases for FP16.toHalf
66         // and have been inspired by the cts HalfTest.
67         // Zeroes, NaN and infinities
68         assertEquals(FP16.POSITIVE_ZERO, FP16.toHalf(0.0f));
69         assertEquals(FP16.NEGATIVE_ZERO, FP16.toHalf(-0.0f));
70         assertEquals(FP16.NaN, FP16.toHalf(Float.NaN));
71         assertEquals(FP16.POSITIVE_INFINITY, FP16.toHalf(Float.POSITIVE_INFINITY));
72         assertEquals(FP16.NEGATIVE_INFINITY, FP16.toHalf(Float.NEGATIVE_INFINITY));
73         // Known values
74         assertEquals((short) 0x3c01, FP16.toHalf(1.0009765625f));
75         assertEquals((short) 0xc000, FP16.toHalf(-2.0f));
76         assertEquals((short) 0x0400, FP16.toHalf(6.10352e-5f));
77         assertEquals((short) 0x7bff, FP16.toHalf(65504.0f));
78         assertEquals((short) 0x3555, FP16.toHalf(1.0f / 3.0f));
79         // Subnormals
80         assertEquals((short) 0x03ff, FP16.toHalf(6.09756e-5f));
81         assertEquals(FP16.MIN_VALUE, FP16.toHalf(5.96046e-8f));
82         assertEquals((short) 0x83ff, FP16.toHalf(-6.09756e-5f));
83         assertEquals((short) 0x8001, FP16.toHalf(-5.96046e-8f));
84         // Subnormals (flushed to +/-0)
85         assertEquals(FP16.POSITIVE_ZERO, FP16.toHalf(5.96046e-9f));
86         assertEquals(FP16.NEGATIVE_ZERO, FP16.toHalf(-5.96046e-9f));
87         // Test for values that overflow the mantissa bits into exp bits
88         assertEquals(0x1000, FP16.toHalf(Float.intBitsToFloat(0x39fff000)));
89         assertEquals(0x0400, FP16.toHalf(Float.intBitsToFloat(0x387fe000)));
90         // Floats with absolute value above +/-65519 are rounded to +/-inf
91         // when using round-to-even
92         assertEquals(0x7bff, FP16.toHalf(65519.0f));
93         assertEquals(0x7bff, FP16.toHalf(65519.9f));
94         assertEquals(FP16.POSITIVE_INFINITY, FP16.toHalf(65520.0f));
95         assertEquals(FP16.NEGATIVE_INFINITY, FP16.toHalf(-65520.0f));
96         // Check if numbers are rounded to nearest even when they
97         // cannot be accurately represented by Half
98         assertEquals(0x6800, FP16.toHalf(2049.0f));
99         assertEquals(0x6c00, FP16.toHalf(4098.0f));
100         assertEquals(0x7000, FP16.toHalf(8196.0f));
101         assertEquals(0x7400, FP16.toHalf(16392.0f));
102         assertEquals(0x7800, FP16.toHalf(32784.0f));
103 
104     }
105 
testToFloat()106     public static void testToFloat(){
107         // FP16 SNaN/QNaN inputs to float
108         // The most significant bit of mantissa:
109         //                 V
110         // 0xfc01: 1 11111 0000000001 (signaling NaN)
111         // 0xfdff: 1 11111 0111111111 (signaling NaN)
112         // 0xfe00: 1 11111 1000000000 (quiet NaN)
113         // 0xffff: 1 11111 1111111111 (quiet NaN)
114         // This test is inspired by Java implementation of android.util.Half.toFloat(),
115         // where the implementation performs SNaN->QNaN conversion.
116         assert(Float.isNaN(FP16.toFloat((short)0xfc01)));
117         assert(Float.isNaN(FP16.toFloat((short)0xfdff)));
118         assert(Float.isNaN(FP16.toFloat((short)0xfe00)));
119         assert(Float.isNaN(FP16.toFloat((short)0xffff)));
120         assertEquals(0xffc02000, TestFP16ToFloatRawIntBits((short)(0xfc01)));  // SNaN->QNaN
121         assertEquals(0xffffe000, TestFP16ToFloatRawIntBits((short)(0xfdff)));  // SNaN->QNaN
122         assertEquals(0xffc00000, TestFP16ToFloatRawIntBits((short)(0xfe00)));  // QNaN->QNaN
123         assertEquals(0xffffe000, TestFP16ToFloatRawIntBits((short)(0xffff)));  // QNaN->QNaN
124     }
125 
testFloor()126     public static void testFloor() {
127         // These tests have been taken from the cts HalfTest
128         assertEquals(FP16.POSITIVE_INFINITY, FP16.floor(FP16.POSITIVE_INFINITY));
129         assertEquals(FP16.NEGATIVE_INFINITY, FP16.floor(FP16.NEGATIVE_INFINITY));
130         assertEquals(FP16.POSITIVE_ZERO, FP16.floor(FP16.POSITIVE_ZERO));
131         assertEquals(FP16.NEGATIVE_ZERO, FP16.floor(FP16.NEGATIVE_ZERO));
132         assertEquals(FP16.NaN, FP16.floor(FP16.NaN));
133         assertEquals(FP16.LOWEST_VALUE, FP16.floor(FP16.LOWEST_VALUE));
134         assertEquals(FP16.POSITIVE_ZERO, FP16.floor(FP16.MIN_NORMAL));
135         assertEquals(FP16.POSITIVE_ZERO, FP16.floor((short) 0x3ff));
136         assertEquals(FP16.POSITIVE_ZERO, FP16.floor(FP16.toHalf(0.2f)));
137         assertEquals(-1.0f, FP16.toFloat(FP16.floor(FP16.toHalf(-0.2f))));
138         assertEquals(-1.0f, FP16.toFloat(FP16.floor(FP16.toHalf(-0.7f))));
139         assertEquals(FP16.POSITIVE_ZERO, FP16.floor(FP16.toHalf(0.7f)));
140         assertEquals(124.0f, FP16.toFloat(FP16.floor(FP16.toHalf(124.7f))));
141         assertEquals(-125.0f, FP16.toFloat(FP16.floor(FP16.toHalf(-124.7f))));
142         assertEquals(124.0f, FP16.toFloat(FP16.floor(FP16.toHalf(124.2f))));
143         assertEquals(-125.0f, FP16.toFloat(FP16.floor(FP16.toHalf(-124.2f))));
144         // floor for NaN values
145         assertEquals((short) 0x7e01, FP16.floor((short) 0x7c01));
146         assertEquals((short) 0x7f00, FP16.floor((short) 0x7d00));
147         assertEquals((short) 0xfe01, FP16.floor((short) 0xfc01));
148         assertEquals((short) 0xff00, FP16.floor((short) 0xfd00));
149     }
150 
testCeil()151     public static void testCeil() {
152         // These tests have been taken from the cts HalfTest
153         assertEquals(FP16.POSITIVE_INFINITY, FP16.ceil(FP16.POSITIVE_INFINITY));
154         assertEquals(FP16.NEGATIVE_INFINITY, FP16.ceil(FP16.NEGATIVE_INFINITY));
155         assertEquals(FP16.POSITIVE_ZERO, FP16.ceil(FP16.POSITIVE_ZERO));
156         assertEquals(FP16.NEGATIVE_ZERO, FP16.ceil(FP16.NEGATIVE_ZERO));
157         assertEquals(FP16.NaN, FP16.ceil(FP16.NaN));
158         assertEquals(FP16.LOWEST_VALUE, FP16.ceil(FP16.LOWEST_VALUE));
159         assertEquals(1.0f, FP16.toFloat(FP16.ceil(FP16.MIN_NORMAL)));
160         assertEquals(1.0f, FP16.toFloat(FP16.ceil((short) 0x3ff)));
161         assertEquals(1.0f, FP16.toFloat(FP16.ceil(FP16.toHalf(0.2f))));
162         assertEquals(FP16.NEGATIVE_ZERO, FP16.ceil(FP16.toHalf(-0.2f)));
163         assertEquals(1.0f, FP16.toFloat(FP16.ceil(FP16.toHalf(0.7f))));
164         assertEquals(FP16.NEGATIVE_ZERO, FP16.ceil(FP16.toHalf(-0.7f)));
165         assertEquals(125.0f, FP16.toFloat(FP16.ceil(FP16.toHalf(124.7f))));
166         assertEquals(-124.0f, FP16.toFloat(FP16.ceil(FP16.toHalf(-124.7f))));
167         assertEquals(125.0f, FP16.toFloat(FP16.ceil(FP16.toHalf(124.2f))));
168         assertEquals(-124.0f, FP16.toFloat(FP16.ceil(FP16.toHalf(-124.2f))));
169         // ceil for NaN values
170         assertEquals((short) 0x7e01, FP16.floor((short) 0x7c01));
171         assertEquals((short) 0x7f00, FP16.floor((short) 0x7d00));
172         assertEquals((short) 0xfe01, FP16.floor((short) 0xfc01));
173         assertEquals((short) 0xff00, FP16.floor((short) 0xfd00));
174     }
175 
testRint()176     public static void testRint() {
177         assertEquals(FP16.POSITIVE_INFINITY, FP16.rint(FP16.POSITIVE_INFINITY));
178         assertEquals(FP16.NEGATIVE_INFINITY, FP16.rint(FP16.NEGATIVE_INFINITY));
179         assertEquals(FP16.POSITIVE_ZERO, FP16.rint(FP16.POSITIVE_ZERO));
180         assertEquals(FP16.NEGATIVE_ZERO, FP16.rint(FP16.NEGATIVE_ZERO));
181         assertEquals(FP16.NaN, FP16.rint(FP16.NaN));
182         assertEquals(FP16.LOWEST_VALUE, FP16.rint(FP16.LOWEST_VALUE));
183         assertEquals(FP16.POSITIVE_ZERO, FP16.rint(FP16.MIN_VALUE));
184         assertEquals(FP16.POSITIVE_ZERO, FP16.rint((short) 0x200));
185         assertEquals(FP16.POSITIVE_ZERO, FP16.rint((short) 0x3ff));
186         assertEquals(FP16.POSITIVE_ZERO, FP16.rint(FP16.toHalf(0.2f)));
187         assertEquals(FP16.NEGATIVE_ZERO, FP16.rint(FP16.toHalf(-0.2f)));
188         assertEquals(1.0f, FP16.toFloat(FP16.rint(FP16.toHalf(0.7f))));
189         assertEquals(-1.0f, FP16.toFloat(FP16.rint(FP16.toHalf(-0.7f))));
190         assertEquals(0.0f, FP16.toFloat(FP16.rint(FP16.toHalf(0.5f))));
191         assertEquals(-0.0f, FP16.toFloat(FP16.rint(FP16.toHalf(-0.5f))));
192         assertEquals(125.0f, FP16.toFloat(FP16.rint(FP16.toHalf(124.7f))));
193         assertEquals(-125.0f, FP16.toFloat(FP16.rint(FP16.toHalf(-124.7f))));
194         assertEquals(124.0f, FP16.toFloat(FP16.rint(FP16.toHalf(124.2f))));
195         assertEquals(-124.0f, FP16.toFloat(FP16.rint(FP16.toHalf(-124.2f))));
196         // floor for NaN values
197         assertEquals((short) 0x7e01, FP16.floor((short) 0x7c01));
198         assertEquals((short) 0x7f00, FP16.floor((short) 0x7d00));
199         assertEquals((short) 0xfe01, FP16.floor((short) 0xfc01));
200         assertEquals((short) 0xff00, FP16.floor((short) 0xfd00));
201 
202     }
203 
testGreater()204     public static void testGreater() {
205         assertTrue(FP16.greater(FP16.POSITIVE_INFINITY, FP16.NEGATIVE_INFINITY));
206         assertTrue(FP16.greater(FP16.POSITIVE_INFINITY, FP16.MAX_VALUE));
207         assertFalse(FP16.greater(FP16.MAX_VALUE, FP16.POSITIVE_INFINITY));
208         assertFalse(FP16.greater(FP16.NEGATIVE_INFINITY, FP16.LOWEST_VALUE));
209         assertTrue(FP16.greater(FP16.LOWEST_VALUE, FP16.NEGATIVE_INFINITY));
210         assertFalse(FP16.greater(FP16.NEGATIVE_ZERO, FP16.POSITIVE_ZERO));
211         assertFalse(FP16.greater(FP16.POSITIVE_ZERO, FP16.NEGATIVE_ZERO));
212         assertFalse(FP16.greater(FP16.toHalf(12.3f), FP16.NaN));
213         assertFalse(FP16.greater(FP16.NaN, FP16.toHalf(12.3f)));
214         assertTrue(FP16.greater(FP16.MIN_NORMAL, FP16.MIN_VALUE));
215         assertFalse(FP16.greater(FP16.MIN_VALUE, FP16.MIN_NORMAL));
216         assertTrue(FP16.greater(FP16.toHalf(12.4f), FP16.toHalf(12.3f)));
217         assertFalse(FP16.greater(FP16.toHalf(12.3f), FP16.toHalf(12.4f)));
218         assertFalse(FP16.greater(FP16.toHalf(-12.4f), FP16.toHalf(-12.3f)));
219         assertTrue(FP16.greater(FP16.toHalf(-12.3f), FP16.toHalf(-12.4f)));
220         assertTrue(FP16.greater((short) 0x3ff, FP16.MIN_VALUE));
221 
222         assertFalse(FP16.greater(FP16.toHalf(-1.0f), FP16.toHalf(0.0f)));
223         assertTrue(FP16.greater(FP16.toHalf(0.0f), FP16.toHalf(-1.0f)));
224         assertFalse(FP16.greater(FP16.toHalf(-1.0f), FP16.toHalf(-1.0f)));
225         assertFalse(FP16.greater(FP16.toHalf(-1.3f), FP16.toHalf(-1.3f)));
226         assertTrue(FP16.greater(FP16.toHalf(1.0f), FP16.toHalf(0.0f)));
227         assertFalse(FP16.greater(FP16.toHalf(0.0f), FP16.toHalf(1.0f)));
228         assertFalse(FP16.greater(FP16.toHalf(1.0f), FP16.toHalf(1.0f)));
229         assertFalse(FP16.greater(FP16.toHalf(1.3f), FP16.toHalf(1.3f)));
230         assertFalse(FP16.greater(FP16.toHalf(-0.1f), FP16.toHalf(0.0f)));
231         assertTrue(FP16.greater(FP16.toHalf(0.0f), FP16.toHalf(-0.1f)));
232         assertFalse(FP16.greater(FP16.toHalf(-0.1f), FP16.toHalf(-0.1f)));
233         assertTrue(FP16.greater(FP16.toHalf(0.1f), FP16.toHalf(0.0f)));
234         assertFalse(FP16.greater(FP16.toHalf(0.0f), FP16.toHalf(0.1f)));
235         assertFalse(FP16.greater(FP16.toHalf(0.1f), FP16.toHalf(0.1f)));
236     }
237 
testGreaterEquals()238     public static void testGreaterEquals() {
239         assertTrue(FP16.greaterEquals(FP16.POSITIVE_INFINITY, FP16.NEGATIVE_INFINITY));
240         assertTrue(FP16.greaterEquals(FP16.POSITIVE_INFINITY, FP16.MAX_VALUE));
241         assertFalse(FP16.greaterEquals(FP16.MAX_VALUE, FP16.POSITIVE_INFINITY));
242         assertFalse(FP16.greaterEquals(FP16.NEGATIVE_INFINITY, FP16.LOWEST_VALUE));
243         assertTrue(FP16.greaterEquals(FP16.LOWEST_VALUE, FP16.NEGATIVE_INFINITY));
244         assertTrue(FP16.greaterEquals(FP16.NEGATIVE_ZERO, FP16.POSITIVE_ZERO));
245         assertTrue(FP16.greaterEquals(FP16.POSITIVE_ZERO, FP16.NEGATIVE_ZERO));
246         assertFalse(FP16.greaterEquals(FP16.toHalf(12.3f), FP16.NaN));
247         assertFalse(FP16.greaterEquals(FP16.NaN, FP16.toHalf(12.3f)));
248         assertTrue(FP16.greaterEquals(FP16.MIN_NORMAL, FP16.MIN_VALUE));
249         assertFalse(FP16.greaterEquals(FP16.MIN_VALUE, FP16.MIN_NORMAL));
250         assertTrue(FP16.greaterEquals(FP16.toHalf(12.4f), FP16.toHalf(12.3f)));
251         assertFalse(FP16.greaterEquals(FP16.toHalf(12.3f), FP16.toHalf(12.4f)));
252         assertFalse(FP16.greaterEquals(FP16.toHalf(-12.4f), FP16.toHalf(-12.3f)));
253         assertTrue(FP16.greaterEquals(FP16.toHalf(-12.3f), FP16.toHalf(-12.4f)));
254         assertTrue(FP16.greaterEquals((short) 0x3ff, FP16.MIN_VALUE));
255         assertTrue(FP16.greaterEquals(FP16.NEGATIVE_INFINITY, FP16.NEGATIVE_INFINITY));
256         assertTrue(FP16.greaterEquals(FP16.POSITIVE_INFINITY, FP16.POSITIVE_INFINITY));
257         assertTrue(FP16.greaterEquals(FP16.toHalf(12.12356f), FP16.toHalf(12.12356f)));
258         assertTrue(FP16.greaterEquals(FP16.toHalf(-12.12356f), FP16.toHalf(-12.12356f)));
259 
260         assertFalse(FP16.greaterEquals(FP16.toHalf(-1.0f), FP16.toHalf(0.0f)));
261         assertTrue(FP16.greaterEquals(FP16.toHalf(0.0f), FP16.toHalf(-1.0f)));
262         assertTrue(FP16.greaterEquals(FP16.toHalf(-1.0f), FP16.toHalf(-1.0f)));
263         assertTrue(FP16.greaterEquals(FP16.toHalf(-1.3f), FP16.toHalf(-1.3f)));
264         assertTrue(FP16.greaterEquals(FP16.toHalf(1.0f), FP16.toHalf(0.0f)));
265         assertFalse(FP16.greaterEquals(FP16.toHalf(0.0f), FP16.toHalf(1.0f)));
266         assertTrue(FP16.greaterEquals(FP16.toHalf(1.0f), FP16.toHalf(1.0f)));
267         assertTrue(FP16.greaterEquals(FP16.toHalf(1.3f), FP16.toHalf(1.3f)));
268         assertFalse(FP16.greaterEquals(FP16.toHalf(-0.1f), FP16.toHalf(0.0f)));
269         assertTrue(FP16.greaterEquals(FP16.toHalf(0.0f), FP16.toHalf(-0.1f)));
270         assertTrue(FP16.greaterEquals(FP16.toHalf(-0.1f), FP16.toHalf(-0.1f)));
271         assertTrue(FP16.greaterEquals(FP16.toHalf(0.1f), FP16.toHalf(0.0f)));
272         assertFalse(FP16.greaterEquals(FP16.toHalf(0.0f), FP16.toHalf(0.1f)));
273         assertTrue(FP16.greaterEquals(FP16.toHalf(0.1f), FP16.toHalf(0.1f)));
274     }
275 
testLess()276     public static void testLess() {
277         assertTrue(FP16.less(FP16.NEGATIVE_INFINITY, FP16.POSITIVE_INFINITY));
278         assertTrue(FP16.less(FP16.MAX_VALUE, FP16.POSITIVE_INFINITY));
279         assertFalse(FP16.less(FP16.POSITIVE_INFINITY, FP16.MAX_VALUE));
280         assertFalse(FP16.less(FP16.LOWEST_VALUE, FP16.NEGATIVE_INFINITY));
281         assertTrue(FP16.less(FP16.NEGATIVE_INFINITY, FP16.LOWEST_VALUE));
282         assertFalse(FP16.less(FP16.POSITIVE_ZERO, FP16.NEGATIVE_ZERO));
283         assertFalse(FP16.less(FP16.NEGATIVE_ZERO, FP16.POSITIVE_ZERO));
284         assertFalse(FP16.less(FP16.NaN, FP16.toHalf(12.3f)));
285         assertFalse(FP16.less(FP16.toHalf(12.3f), FP16.NaN));
286         assertTrue(FP16.less(FP16.MIN_VALUE, FP16.MIN_NORMAL));
287         assertFalse(FP16.less(FP16.MIN_NORMAL, FP16.MIN_VALUE));
288         assertTrue(FP16.less(FP16.toHalf(12.3f), FP16.toHalf(12.4f)));
289         assertFalse(FP16.less(FP16.toHalf(12.4f), FP16.toHalf(12.3f)));
290         assertFalse(FP16.less(FP16.toHalf(-12.3f), FP16.toHalf(-12.4f)));
291         assertTrue(FP16.less(FP16.toHalf(-12.4f), FP16.toHalf(-12.3f)));
292         assertTrue(FP16.less(FP16.MIN_VALUE, (short) 0x3ff));
293 
294         assertTrue(FP16.less(FP16.toHalf(-1.0f), FP16.toHalf(0.0f)));
295         assertFalse(FP16.less(FP16.toHalf(0.0f), FP16.toHalf(-1.0f)));
296         assertFalse(FP16.less(FP16.toHalf(-1.0f), FP16.toHalf(-1.0f)));
297         assertFalse(FP16.less(FP16.toHalf(-1.3f), FP16.toHalf(-1.3f)));
298         assertFalse(FP16.less(FP16.toHalf(1.0f), FP16.toHalf(0.0f)));
299         assertTrue(FP16.less(FP16.toHalf(0.0f), FP16.toHalf(1.0f)));
300         assertFalse(FP16.less(FP16.toHalf(1.0f), FP16.toHalf(1.0f)));
301         assertFalse(FP16.less(FP16.toHalf(1.3f), FP16.toHalf(1.3f)));
302         assertTrue(FP16.less(FP16.toHalf(-0.1f), FP16.toHalf(0.0f)));
303         assertFalse(FP16.less(FP16.toHalf(0.0f), FP16.toHalf(-0.1f)));
304         assertFalse(FP16.less(FP16.toHalf(-0.1f), FP16.toHalf(-0.1f)));
305         assertFalse(FP16.less(FP16.toHalf(0.1f), FP16.toHalf(0.0f)));
306         assertTrue(FP16.less(FP16.toHalf(0.0f), FP16.toHalf(0.1f)));
307         assertFalse(FP16.less(FP16.toHalf(0.1f), FP16.toHalf(0.1f)));
308     }
309 
testLessEquals()310     public static void testLessEquals() {
311         assertTrue(FP16.lessEquals(FP16.NEGATIVE_INFINITY, FP16.POSITIVE_INFINITY));
312         assertTrue(FP16.lessEquals(FP16.MAX_VALUE, FP16.POSITIVE_INFINITY));
313         assertFalse(FP16.lessEquals(FP16.POSITIVE_INFINITY, FP16.MAX_VALUE));
314         assertFalse(FP16.lessEquals(FP16.LOWEST_VALUE, FP16.NEGATIVE_INFINITY));
315         assertTrue(FP16.lessEquals(FP16.NEGATIVE_INFINITY, FP16.LOWEST_VALUE));
316         assertTrue(FP16.lessEquals(FP16.POSITIVE_ZERO, FP16.NEGATIVE_ZERO));
317         assertTrue(FP16.lessEquals(FP16.NEGATIVE_ZERO, FP16.POSITIVE_ZERO));
318         assertFalse(FP16.lessEquals(FP16.NaN, FP16.toHalf(12.3f)));
319         assertFalse(FP16.lessEquals(FP16.toHalf(12.3f), FP16.NaN));
320         assertTrue(FP16.lessEquals(FP16.MIN_VALUE, FP16.MIN_NORMAL));
321         assertFalse(FP16.lessEquals(FP16.MIN_NORMAL, FP16.MIN_VALUE));
322         assertTrue(FP16.lessEquals(FP16.toHalf(12.3f), FP16.toHalf(12.4f)));
323         assertFalse(FP16.lessEquals(FP16.toHalf(12.4f), FP16.toHalf(12.3f)));
324         assertFalse(FP16.lessEquals(FP16.toHalf(-12.3f), FP16.toHalf(-12.4f)));
325         assertTrue(FP16.lessEquals(FP16.toHalf(-12.4f), FP16.toHalf(-12.3f)));
326         assertTrue(FP16.lessEquals(FP16.MIN_VALUE, (short) 0x3ff));
327         assertTrue(FP16.lessEquals(FP16.NEGATIVE_INFINITY, FP16.NEGATIVE_INFINITY));
328         assertTrue(FP16.lessEquals(FP16.POSITIVE_INFINITY, FP16.POSITIVE_INFINITY));
329         assertTrue(FP16.lessEquals(FP16.toHalf(12.12356f), FP16.toHalf(12.12356f)));
330         assertTrue(FP16.lessEquals(FP16.toHalf(-12.12356f), FP16.toHalf(-12.12356f)));
331 
332         assertTrue(FP16.lessEquals(FP16.toHalf(-1.0f), FP16.toHalf(0.0f)));
333         assertFalse(FP16.lessEquals(FP16.toHalf(0.0f), FP16.toHalf(-1.0f)));
334         assertTrue(FP16.lessEquals(FP16.toHalf(-1.0f), FP16.toHalf(-1.0f)));
335         assertTrue(FP16.lessEquals(FP16.toHalf(-1.3f), FP16.toHalf(-1.3f)));
336         assertFalse(FP16.lessEquals(FP16.toHalf(1.0f), FP16.toHalf(0.0f)));
337         assertTrue(FP16.lessEquals(FP16.toHalf(0.0f), FP16.toHalf(1.0f)));
338         assertTrue(FP16.lessEquals(FP16.toHalf(1.0f), FP16.toHalf(1.0f)));
339         assertTrue(FP16.lessEquals(FP16.toHalf(1.3f), FP16.toHalf(1.3f)));
340         assertTrue(FP16.lessEquals(FP16.toHalf(-0.1f), FP16.toHalf(0.0f)));
341         assertFalse(FP16.lessEquals(FP16.toHalf(0.0f), FP16.toHalf(-0.1f)));
342         assertTrue(FP16.lessEquals(FP16.toHalf(-0.1f), FP16.toHalf(-0.1f)));
343         assertFalse(FP16.lessEquals(FP16.toHalf(0.1f), FP16.toHalf(0.0f)));
344         assertTrue(FP16.lessEquals(FP16.toHalf(0.0f), FP16.toHalf(0.1f)));
345         assertTrue(FP16.lessEquals(FP16.toHalf(0.1f), FP16.toHalf(0.1f)));
346     }
347 
main(String args[])348     public static void main(String args[]) {
349         testHalfToFloatToHalfConversions();
350         testToHalf();
351         testToFloat();
352         testFloor();
353         testCeil();
354         testRint();
355         testGreater();
356         testGreaterEquals();
357         testLessEquals();
358         testLess();
359     }
360 }
361