1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16function testNegativeZeroMod(a, b, c) { 17 var temp = a * b; 18 return temp % c; 19} 20 21function testNegativeZeroMul(a, b) { 22 var temp = a * b; 23 return temp; 24} 25 26function testNegativeZeroDiv(a, b, c) { 27 var temp = a * b; 28 return temp / c; 29} 30 31for (var i = 1; i < 100; i++) { 32 var result = 0; 33 result = testNegativeZeroMod(i, 5, 5); 34 if (result !== 0) { 35 throw "testNegativeZeroMod(i, 5, 5), returned: " + result; 36 } 37 result = testNegativeZeroMul(i, 0); 38 if (result !== 0) { 39 throw "testNegativeZeroMul(i, 0), returned: " + result; 40 } 41 result = testNegativeZeroDiv(0, i, i); 42 if (result !== 0) { 43 throw "testNegativeZeroDiv(0, i, i), returned: " + result; 44 } 45} 46 47ArkTools.jitCompileAsync(testNegativeZeroMod); 48ArkTools.jitCompileAsync(testNegativeZeroMul); 49ArkTools.jitCompileAsync(testNegativeZeroDiv); 50print(ArkTools.waitJitCompileFinish(testNegativeZeroMod)); 51print(ArkTools.waitJitCompileFinish(testNegativeZeroMul)); 52print(ArkTools.waitJitCompileFinish(testNegativeZeroDiv)); 53 54for (var i = 1; i < 100; i++) { 55 var result = 0; 56 result = testNegativeZeroMod(-i, 0, 2); 57 if (!(result === 0 && (1 / result) === -Infinity)) { 58 throw "testNegativeZeroMod(-i, 0, 2), returned: " + result; 59 } 60 result = testNegativeZeroMul(-i, 0); 61 if (!(result === 0 && (1 / result) === -Infinity)) { 62 throw "testNegativeZeroMul(-i, 0), returned: " + result; 63 } 64 result = testNegativeZeroDiv(0, -i, i); 65 if (!(result === 0 && (1 / result) === -Infinity)) { 66 throw "testNegativeZeroDiv(0, -i, i), returned: " + result; 67 } 68} 69