1.1 --- a/rt/emul/mini/src/main/java/java/lang/Math.java Tue Jan 20 12:26:35 2015 +0100
1.2 +++ b/rt/emul/mini/src/main/java/java/lang/Math.java Tue Jan 20 13:01:31 2015 +0100
1.3 @@ -25,6 +25,7 @@
1.4
1.5 package java.lang;
1.6
1.7 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
1.8 import org.apidesign.bck2brwsr.core.JavaScriptBody;
1.9
1.10
1.11 @@ -85,6 +86,10 @@
1.12 * @since JDK1.0
1.13 */
1.14
1.15 +@ExtraJavaScript(
1.16 + resource="/org/apidesign/vm4brwsr/emul/lang/java_lang_Math.js",
1.17 + processByteCode=true
1.18 +)
1.19 public final class Math {
1.20
1.21 /**
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/rt/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Math.js Tue Jan 20 13:01:31 2015 +0100
2.3 @@ -0,0 +1,5 @@
2.4 +
2.5 +vm['java_lang_StrictMath'] = vm.java_lang_Math;
2.6 +if (typeof exports !== 'undefined') {
2.7 + exports['java_lang_StrictMath'] = vm.java_lang_Math;
2.8 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/MathStrictTest.java Tue Jan 20 13:01:31 2015 +0100
3.3 @@ -0,0 +1,27 @@
3.4 +/**
3.5 + * Back 2 Browser Bytecode Translator
3.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3.7 + *
3.8 + * This program is free software: you can redistribute it and/or modify
3.9 + * it under the terms of the GNU General Public License as published by
3.10 + * the Free Software Foundation, version 2 of the License.
3.11 + *
3.12 + * This program is distributed in the hope that it will be useful,
3.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3.15 + * GNU General Public License for more details.
3.16 + *
3.17 + * You should have received a copy of the GNU General Public License
3.18 + * along with this program. Look for COPYING file in the top folder.
3.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
3.20 + */
3.21 +package org.apidesign.vm4brwsr;
3.22 +
3.23 +/**
3.24 + */
3.25 +public class MathStrictTest extends MathTest {
3.26 + @Override
3.27 + protected Class<?> mathClass() {
3.28 + return StrictMath.class;
3.29 + }
3.30 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/MathTest.java Tue Jan 20 13:01:31 2015 +0100
4.3 @@ -0,0 +1,115 @@
4.4 +/**
4.5 + * Back 2 Browser Bytecode Translator
4.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
4.7 + *
4.8 + * This program is free software: you can redistribute it and/or modify
4.9 + * it under the terms of the GNU General Public License as published by
4.10 + * the Free Software Foundation, version 2 of the License.
4.11 + *
4.12 + * This program is distributed in the hope that it will be useful,
4.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.15 + * GNU General Public License for more details.
4.16 + *
4.17 + * You should have received a copy of the GNU General Public License
4.18 + * along with this program. Look for COPYING file in the top folder.
4.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
4.20 + */
4.21 +package org.apidesign.vm4brwsr;
4.22 +
4.23 +import org.testng.annotations.AfterClass;
4.24 +import org.testng.annotations.BeforeClass;
4.25 +import org.testng.annotations.Test;
4.26 +
4.27 +/** Checks behavior on Math class.
4.28 + *
4.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
4.30 + */
4.31 +public class MathTest {
4.32 + @Test public void rintNegativeUp() throws Exception {
4.33 + final double cnts = -453904.634;
4.34 + assertExec("Should round up to end with 5", mathClass(), "rint__DD",
4.35 + -453905.0, cnts
4.36 + );
4.37 + }
4.38 +
4.39 + protected Class<?> mathClass() {
4.40 + return Math.class;
4.41 + }
4.42 +
4.43 + @Test public void rintNegativeDown() throws Exception {
4.44 + final double cnts = -453904.434;
4.45 + assertExec("Should round up to end with 4", mathClass(), "rint__DD",
4.46 + -453904.0, cnts
4.47 + );
4.48 + }
4.49 +
4.50 + @Test public void rintPositiveUp() throws Exception {
4.51 + final double cnts = 453904.634;
4.52 + assertExec("Should round up to end with 5", mathClass(), "rint__DD",
4.53 + 453905.0, cnts
4.54 + );
4.55 + }
4.56 + @Test public void rintPositiveDown() throws Exception {
4.57 + final double cnts = 453904.434;
4.58 + assertExec("Should round up to end with 4", mathClass(), "rint__DD",
4.59 + 453904.0, cnts
4.60 + );
4.61 + }
4.62 + @Test public void rintOneHalf() throws Exception {
4.63 + final double cnts = 1.5;
4.64 + assertExec("Should round up to end with 2", mathClass(), "rint__DD",
4.65 + 2.0, cnts
4.66 + );
4.67 + }
4.68 + @Test public void rintNegativeOneHalf() throws Exception {
4.69 + final double cnts = -1.5;
4.70 + assertExec("Should round up to end with 2", mathClass(), "rint__DD",
4.71 + -2.0, cnts
4.72 + );
4.73 + }
4.74 + @Test public void rintTwoAndHalf() throws Exception {
4.75 + final double cnts = 2.5;
4.76 + assertExec("Should round up to end with 2", mathClass(), "rint__DD",
4.77 + 2.0, cnts
4.78 + );
4.79 + }
4.80 + @Test public void rintNegativeTwoOneHalf() throws Exception {
4.81 + final double cnts = -2.5;
4.82 + assertExec("Should round up to end with 2", mathClass(), "rint__DD",
4.83 + -2.0, cnts
4.84 + );
4.85 + }
4.86 +
4.87 + @Test public void ieeeReminder1() throws Exception {
4.88 + assertExec("Same result 1", mathClass(), "IEEEremainder__DDD",
4.89 + Math.IEEEremainder(10.0, 4.5), 10.0, 4.5
4.90 + );
4.91 + }
4.92 +
4.93 + @Test public void ieeeReminder2() throws Exception {
4.94 + assertExec("Same result 1", mathClass(), "IEEEremainder__DDD",
4.95 + Math.IEEEremainder(Integer.MAX_VALUE, -4.5), Integer.MAX_VALUE, -4.5
4.96 + );
4.97 + }
4.98 +
4.99 + private static TestVM code;
4.100 +
4.101 + @BeforeClass
4.102 + public static void compileTheCode() throws Exception {
4.103 + StringBuilder sb = new StringBuilder();
4.104 + code = TestVM.compileClass(sb);
4.105 + }
4.106 + @AfterClass
4.107 + public static void releaseTheCode() {
4.108 + code = null;
4.109 + }
4.110 +
4.111 + private void assertExec(
4.112 + String msg, Class<?> clazz, String method,
4.113 + Object ret, Object... args
4.114 + ) throws Exception {
4.115 + code.assertExec(msg, clazz, method, ret, args);
4.116 + }
4.117 +
4.118 +}
5.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java Tue Jan 20 12:26:35 2015 +0100
5.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java Tue Jan 20 13:01:31 2015 +0100
5.3 @@ -79,89 +79,6 @@
5.4 );
5.5 }
5.6
5.7 - @Test public void rintNegativeUp() throws Exception {
5.8 - final double cnts = -453904.634;
5.9 - assertExec(
5.10 - "Should round up to end with 5",
5.11 - Math.class, "rint__DD",
5.12 - -453905.0, cnts
5.13 - );
5.14 - }
5.15 -
5.16 - @Test public void rintNegativeDown() throws Exception {
5.17 - final double cnts = -453904.434;
5.18 - assertExec(
5.19 - "Should round up to end with 4",
5.20 - Math.class, "rint__DD",
5.21 - -453904.0, cnts
5.22 - );
5.23 - }
5.24 -
5.25 - @Test public void rintPositiveUp() throws Exception {
5.26 - final double cnts = 453904.634;
5.27 - assertExec(
5.28 - "Should round up to end with 5",
5.29 - Math.class, "rint__DD",
5.30 - 453905.0, cnts
5.31 - );
5.32 - }
5.33 - @Test public void rintPositiveDown() throws Exception {
5.34 - final double cnts = 453904.434;
5.35 - assertExec(
5.36 - "Should round up to end with 4",
5.37 - Math.class, "rint__DD",
5.38 - 453904.0, cnts
5.39 - );
5.40 - }
5.41 - @Test public void rintOneHalf() throws Exception {
5.42 - final double cnts = 1.5;
5.43 - assertExec(
5.44 - "Should round up to end with 2",
5.45 - Math.class, "rint__DD",
5.46 - 2.0, cnts
5.47 - );
5.48 - }
5.49 - @Test public void rintNegativeOneHalf() throws Exception {
5.50 - final double cnts = -1.5;
5.51 - assertExec(
5.52 - "Should round up to end with 2",
5.53 - Math.class, "rint__DD",
5.54 - -2.0, cnts
5.55 - );
5.56 - }
5.57 - @Test public void rintTwoAndHalf() throws Exception {
5.58 - final double cnts = 2.5;
5.59 - assertExec(
5.60 - "Should round up to end with 2",
5.61 - Math.class, "rint__DD",
5.62 - 2.0, cnts
5.63 - );
5.64 - }
5.65 - @Test public void rintNegativeTwoOneHalf() throws Exception {
5.66 - final double cnts = -2.5;
5.67 - assertExec(
5.68 - "Should round up to end with 2",
5.69 - Math.class, "rint__DD",
5.70 - -2.0, cnts
5.71 - );
5.72 - }
5.73 -
5.74 - @Test public void ieeeReminder1() throws Exception {
5.75 - assertExec(
5.76 - "Same result 1",
5.77 - Math.class, "IEEEremainder__DDD",
5.78 - Math.IEEEremainder(10.0, 4.5), 10.0, 4.5
5.79 - );
5.80 - }
5.81 -
5.82 - @Test public void ieeeReminder2() throws Exception {
5.83 - assertExec(
5.84 - "Same result 1",
5.85 - Math.class, "IEEEremainder__DDD",
5.86 - Math.IEEEremainder(Integer.MAX_VALUE, -4.5), Integer.MAX_VALUE, -4.5
5.87 - );
5.88 - }
5.89 -
5.90 @Test public void divAndRound() throws Exception {
5.91 assertExec(
5.92 "Should be rounded to one",