PageRenderTime 1348ms CodeModel.GetById 137ms app.highlight 954ms RepoModel.GetById 56ms app.codeStats 0ms

/src/xmlvm2csharp/test/org/xmlvm/test/nativeImpl/FloatTest.java

https://github.com/tisoft/xmlvm
Java | 86 lines | 57 code | 4 blank | 25 comment | 6 complexity | d00cf751ea3ce9347c3ae76d53a07a44 MD5 | raw file
 1/* Copyright (c) 2002-2011 by XMLVM.org
 2 *
 3 * Project Info:  http://www.xmlvm.org
 4 *
 5 * This program is free software; you can redistribute it and/or modify it
 6 * under the terms of the GNU Lesser General Public License as published by
 7 * the Free Software Foundation; either version 2.1 of the License, or
 8 * (at your option) any later version.
 9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13 * License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
18 * USA.
19 */
20package org.xmlvm.test.nativeImpl;
21
22/*
23 * tests native implementation of java.lang.Float
24 */
25public class FloatTest {
26    public static void main(String[] args) {
27        int numTests = 14;
28        String[] description = new String[numTests];
29        boolean[] result = new boolean[numTests];
30        int i = -1;
31
32        // floatToIntBits:
33        i++;
34        result[i] = Float.floatToIntBits(Float.NaN) == 0x7FC00000;
35        description[i] = "floatToIntBits(NaN) == 0x7FC00000";
36        i++;
37        result[i] = Float.floatToIntBits(Float.POSITIVE_INFINITY) == 0x7F800000;
38        description[i] = "floatToIntBits(+Infinity) == 0x7F800000";
39        i++;
40        result[i] = Float.floatToIntBits(Float.NEGATIVE_INFINITY) == 0xFF800000;
41        description[i] = "floatToIntBits(-Infinity) == 0x0xFF800000";
42        i++;
43        result[i] = Float.compare(Float.intBitsToFloat(Float.floatToIntBits(1.546F)),1.546F)==0;
44        description[i] = "longBitsToFloat(floatToIntBits(x))==x, for some x";
45        i++;
46        result[i] = Float.floatToIntBits(-1.461381E-12F) == 0xABCDABCD;
47        description[i] = "floatToIntBits(-1.461381E-12) == 0xABCDABCD";
48
49        // intBitsToFloat:
50        i++;
51        result[i] = Float.compare(Float.intBitsToFloat(0x7F800000),
52                                   Float.POSITIVE_INFINITY)==0;
53        description[i] = "intBitsToFloat(0x7F800000)==+Infinity";
54        i++;
55        result[i] = Float.compare(Float.intBitsToFloat(0xFF800000),
56                                   Float.NEGATIVE_INFINITY)==0;
57        description[i] = "intBitsToFloat(0xFF800000)==-Infinity";
58        i++;
59        result[i] = Float.isNaN(Float.intBitsToFloat(0x7F800001));
60        description[i] = "intBitsToFloat(0x7F800001)==NaN";
61        i++;
62        result[i] = Float.isNaN(Float.intBitsToFloat(0x7FABCDEF));
63        description[i] = "intBitsToFloat(0x7FABCDEF)==NaN";
64        i++;
65        result[i] = Float.isNaN(Float.intBitsToFloat(0x7FFFFFFF));
66        description[i] = "intBitsToFloat(0x7FFFFFFF)==NaN";
67        i++;
68        result[i] = Float.isNaN(Float.intBitsToFloat(0xFF800001));
69        description[i] = "intBitsToFloat(0xFF800001)==NaN";
70        i++;
71        result[i] = Float.isNaN(Float.intBitsToFloat(0xFFABCDEF));
72        description[i] = "intBitsToFloat(0xFFABCDEF)==NaN";
73        i++;
74        result[i] = Float.isNaN(Float.intBitsToFloat(0xFFFFFFFF));
75        description[i] = "intBitsToFloat(0xFFFFFFFF)==NaN";
76        i++;
77        result[i] = Float.compare(Float.intBitsToFloat(0x12341234), 5.682042E-28F) == 0;
78        description[i] = "intBitsToFloat(0x12341234)==5.682042E-28";
79
80        // print results
81        for (int j=0; j<numTests; j++) {
82            System.out.println(j + ") "
83                    + (result[j] ? "passed" : "failed") + ": "+ description[j]);
84        }
85    }
86}