PageRenderTime 110ms CodeModel.GetById 20ms app.highlight 10ms RepoModel.GetById 70ms app.codeStats 0ms

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

https://github.com/tisoft/xmlvm
Java | 94 lines | 63 code | 6 blank | 25 comment | 6 complexity | 66b994d476ca4e10890d63cc4b15055e 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 methods in java.lang.Double
24 */
25public class DoubleTest {
26    public static void main(String[] args) {
27        int numTests = 16;
28        String[] description = new String[numTests];
29        boolean[] result = new boolean[numTests];
30        int i = -1;
31        // doubleToLongBits:
32        i++;
33        result[i] = Double.doubleToLongBits(Double.NaN) == 0x7FF8000000000000L;
34        description[i] = "doubleToLongBits(NaN) == 0x7FF8000000000000L";
35        i++;
36        result[i] = Double.doubleToLongBits(Double.POSITIVE_INFINITY) == 0x7FF0000000000000L;
37        description[i] = "doubleToLongBits(+Infinity) == 0x7FF0000000000000L";
38        i++;
39        result[i] = Double.doubleToLongBits(Double.NEGATIVE_INFINITY) == 0xFFF0000000000000L;
40        description[i] = "doubleToLongBits(-Infinity) == 0xFFF0000000000000L";
41        i++;
42        result[i] = Double.compare(Double.longBitsToDouble(Double.doubleToLongBits(Math.PI/7)),Math.PI/7)==0;
43        description[i] = "longBitsToDouble(doubleToLongBits(x))==x, for some x";
44        i++;
45        result[i] = Double.doubleToLongBits(Math.PI/7)==0x3FDCB91F3BBBA140L;
46        description[i] = "doubleToLongBits(pi/7)==0x3FDCB91F3BBBA140";
47        i++;
48        result[i] = Double.doubleToLongBits(5.626349108908516E-221) == 0x1234567890ABCDEFL;
49        description[i] = "doubleToLongBits(5.626349108908516E-221) == 0x1234567890ABCDEF";
50        i++;
51        result[i] = Double.doubleToLongBits(Math.sqrt(Math.E)) == 0x3FFA61298E1E069CL;
52        description[i] = "doubleToLongBits(sqrt(e)) == 0x3FFA61298E1E069C";
53
54        // longBitsToDouble:
55        i++;
56        result[i] = Double.compare(Double.longBitsToDouble(0x7FF0000000000000L),
57                                   Double.POSITIVE_INFINITY)==0;
58        description[i] = "longBitsToDouble(0x7FF0000000000000L)==+Infinity";
59        i++;
60        result[i] = Double.compare(Double.longBitsToDouble(0xFFF0000000000000L),
61                                   Double.NEGATIVE_INFINITY)==0;
62        description[i] = "longBitsToDouble(0xFFF0000000000000L)==-Infinity";
63        i++;
64        result[i] = Double.isNaN(Double.longBitsToDouble(0x7FF0000000000001L));
65        description[i] = "longBitsToDouble(0x7FF0000000000001L)==NaN";
66        i++;
67        result[i] = Double.isNaN(Double.longBitsToDouble(0x7FF123456789ABCDL));
68        description[i] = "longBitsToDouble(0x7FF123456789ABCDL)==NaN";
69        i++;
70        result[i] = Double.isNaN(Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL));
71        description[i] = "longBitsToDouble(0x7FFFFFFFFFFFFFFFL)==NaN";
72        i++;
73        result[i] = Double.isNaN(Double.longBitsToDouble(0xFFF0000000000001L));
74        description[i] = "longBitsToDouble(0xFFF0000000000001L)==NaN";
75        i++;
76        result[i] = Double.isNaN(Double.longBitsToDouble(0xFFF123456789ABCDL));
77        description[i] = "longBitsToDouble(0xFFF123456789ABCDL)==NaN";
78        i++;
79        result[i] = Double.isNaN(Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL));
80        description[i] = "longBitsToDouble(0xFFFFFFFFFFFFFFFFL)==NaN";
81        i++;
82        result[i] = Double.compare(Double.longBitsToDouble(0x13579BDF02468ACEL),1.7121363327076063E-215)==0;
83        description[i] = "longBitsToDouble(0x13579BDF02468ACE)==1.7121363327076063E-215";
84
85        // print results
86        for (int j=0; j<numTests; j++) {
87            System.out.println(j + ") "
88                    + (result[j] ? "passed" : "failed") + ": "+ description[j]);
89        }
90
91    }
92
93
94}