test/java/lang/Math/Rint.java

Print this page




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4101566 4831589
  27  * @summary Check for correct implementation of Math.rint(double)
  28  */
  29 
  30 import sun.misc.DoubleConsts;
  31 
  32 public class Rint {
  33 
  34     static int testRintCase(double input, double expected) {
  35         int failures = 0;
  36         double result;
  37         failures += Tests.test("Math.rint",  input, Math.rint(input),   expected);
  38         failures += Tests.test("Math.rint", -input, Math.rint(-input), -expected);
  39         failures += Tests.test("StrictMath.rint",
  40                                input, StrictMath.rint(input),   expected);
  41         failures += Tests.test("StrictMath.rint", -input,
  42                                StrictMath.rint(-input), -expected);
  43         return failures;
  44     }
  45 
  46 
  47     public static void main(String args[]) {
  48         int failures = 0;
  49         double twoToThe52 = Math.scalb(1.0, 52); // 2^52
  50 
  51         double [][] testCases = {
  52             {0.0,                               0.0},
  53             {Double.MIN_VALUE,                  0.0},
  54             {Math.nextDown(DoubleConsts.MIN_NORMAL), 0.0},
  55             {DoubleConsts.MIN_NORMAL,           0.0},
  56 
  57             {0.2,                               0.0},
  58 
  59             {Math.nextDown(0.5),             0.0},
  60             {              0.5,              0.0},
  61             {  Math.nextUp(0.5),             1.0},
  62 
  63             {0.7,                               1.0},
  64             {Math.nextDown(1.0),             1.0},
  65             {              1.0,              1.0},
  66             {  Math.nextUp(1.0),             1.0},
  67 
  68             {Math.nextDown(1.5),             1.0},
  69             {              1.5,              2.0},
  70             {  Math.nextUp(1.5),             2.0},
  71 
  72             {4.2,                               4.0},
  73             {4.5,                               4.0},
  74             {4.7,                               5.0},
  75 




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4101566 4831589
  27  * @summary Check for correct implementation of Math.rint(double)
  28  */
  29 


  30 public class Rint {
  31 
  32     static int testRintCase(double input, double expected) {
  33         int failures = 0;
  34         double result;
  35         failures += Tests.test("Math.rint",  input, Math.rint(input),   expected);
  36         failures += Tests.test("Math.rint", -input, Math.rint(-input), -expected);
  37         failures += Tests.test("StrictMath.rint",
  38                                input, StrictMath.rint(input),   expected);
  39         failures += Tests.test("StrictMath.rint", -input,
  40                                StrictMath.rint(-input), -expected);
  41         return failures;
  42     }
  43 
  44 
  45     public static void main(String args[]) {
  46         int failures = 0;
  47         double twoToThe52 = Math.scalb(1.0, 52); // 2^52
  48 
  49         double [][] testCases = {
  50             {0.0,                               0.0},
  51             {Double.MIN_VALUE,                  0.0},
  52             {Math.nextDown(Double.MIN_NORMAL),  0.0},
  53             {Double.MIN_NORMAL,                 0.0},
  54 
  55             {0.2,                               0.0},
  56 
  57             {Math.nextDown(0.5),             0.0},
  58             {              0.5,              0.0},
  59             {  Math.nextUp(0.5),             1.0},
  60 
  61             {0.7,                               1.0},
  62             {Math.nextDown(1.0),             1.0},
  63             {              1.0,              1.0},
  64             {  Math.nextUp(1.0),             1.0},
  65 
  66             {Math.nextDown(1.5),             1.0},
  67             {              1.5,              2.0},
  68             {  Math.nextUp(1.5),             2.0},
  69 
  70             {4.2,                               4.0},
  71             {4.5,                               4.0},
  72             {4.7,                               5.0},
  73