test/jdk/java/math/BigInteger/PrimitiveConversionTests.java
changeset 52789 a051c5c8aa56
parent 47216 71c04702a3d5
equal deleted inserted replaced
52788:241b8151b6b6 52789:a051c5c8aa56
     1 /*
     1 /*
     2  * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    61 
    61 
    62         ALL_BIGINTEGER_CANDIDATES = Collections.unmodifiableList(samples);
    62         ALL_BIGINTEGER_CANDIDATES = Collections.unmodifiableList(samples);
    63     }
    63     }
    64 
    64 
    65     public static int testDoubleValue() {
    65     public static int testDoubleValue() {
       
    66         System.out.println("--- testDoubleValue ---");
    66         int failures = 0;
    67         int failures = 0;
    67         for (BigInteger big : ALL_BIGINTEGER_CANDIDATES) {
    68         for (BigInteger big : ALL_BIGINTEGER_CANDIDATES) {
    68             double expected = Double.parseDouble(big.toString());
    69             double expected = Double.parseDouble(big.toString());
    69             double actual = big.doubleValue();
    70             double actual = big.doubleValue();
    70 
    71 
    71             // should be bitwise identical
    72             // should be bitwise identical
    72             if (Double.doubleToRawLongBits(expected) != Double
    73             if (Double.doubleToRawLongBits(expected) != Double
    73                     .doubleToRawLongBits(actual)) {
    74                     .doubleToRawLongBits(actual)) {
    74                 System.out.println(big);
    75                 System.out.format("big: %s, expected: %f, actual: %f%n",
       
    76                     big, expected, actual);
    75                 failures++;
    77                 failures++;
    76             }
    78             }
    77         }
    79         }
    78         return failures;
    80         return failures;
    79     }
    81     }
    80 
    82 
    81     public static int testFloatValue() {
    83     public static int testFloatValue() {
       
    84         System.out.println("--- testFloatValue ---");
    82         int failures = 0;
    85         int failures = 0;
    83         for (BigInteger big : ALL_BIGINTEGER_CANDIDATES) {
    86         for (BigInteger big : ALL_BIGINTEGER_CANDIDATES) {
    84             float expected = Float.parseFloat(big.toString());
    87             float expected = Float.parseFloat(big.toString());
    85             float actual = big.floatValue();
    88             float actual = big.floatValue();
    86 
    89 
    87             // should be bitwise identical
    90             // should be bitwise identical
    88             if (Float.floatToRawIntBits(expected) != Float
    91             if (Float.floatToRawIntBits(expected) != Float
    89                     .floatToRawIntBits(actual)) {
    92                     .floatToRawIntBits(actual)) {
    90                 System.out.println(big + " " + expected + " " + actual);
    93                 System.out.format("big: %s, expected: %f, actual: %f%n",
       
    94                     big, expected, actual);
    91                 failures++;
    95                 failures++;
    92             }
    96             }
    93         }
    97         }
    94         return failures;
    98         return failures;
    95     }
    99     }