14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_cideclare interface ArkTools { 174514f5e3Sopenharmony_ci isAOTCompiled(args: any): boolean; 184514f5e3Sopenharmony_ci} 194514f5e3Sopenharmony_cideclare function print(arg:any):string; 204514f5e3Sopenharmony_cifunction replace(a : number) 214514f5e3Sopenharmony_ci{ 224514f5e3Sopenharmony_ci return a; 234514f5e3Sopenharmony_ci} 244514f5e3Sopenharmony_ci 254514f5e3Sopenharmony_cifunction printZero(x: any) { 264514f5e3Sopenharmony_ci if (Object.is(x, -0)) { 274514f5e3Sopenharmony_ci print("-0"); 284514f5e3Sopenharmony_ci } else { 294514f5e3Sopenharmony_ci print(x); 304514f5e3Sopenharmony_ci } 314514f5e3Sopenharmony_ci} 324514f5e3Sopenharmony_ci 334514f5e3Sopenharmony_cifunction doFround(x: any): number { 344514f5e3Sopenharmony_ci return Math.fround(x); 354514f5e3Sopenharmony_ci} 364514f5e3Sopenharmony_ci 374514f5e3Sopenharmony_cifunction printFround(x: any) { 384514f5e3Sopenharmony_ci try { 394514f5e3Sopenharmony_ci print(doFround(x)); 404514f5e3Sopenharmony_ci } finally { 414514f5e3Sopenharmony_ci } 424514f5e3Sopenharmony_ci} 434514f5e3Sopenharmony_ci 444514f5e3Sopenharmony_ci// Check without params 454514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 464514f5e3Sopenharmony_ciprint(Math.fround()); //: NaN 474514f5e3Sopenharmony_ci 484514f5e3Sopenharmony_ci// Check with single int param 494514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 504514f5e3Sopenharmony_ciprint(Math.fround(0)); //: 0 514514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 524514f5e3Sopenharmony_ciprint(Math.fround(3)); //: 3 534514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 544514f5e3Sopenharmony_ciprint(Math.fround(-5)); //: -5 554514f5e3Sopenharmony_ci 564514f5e3Sopenharmony_ci// Test large ints 574514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 584514f5e3Sopenharmony_ciprint(Math.fround(1073741824)) //: 1073741824 594514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 604514f5e3Sopenharmony_ciprint(Math.fround(1073741804)) //: 1073741824 614514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 624514f5e3Sopenharmony_ciprint(Math.fround(1073741784)) //: 1073741760 634514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 644514f5e3Sopenharmony_ciprint(Math.fround(-1073741804)) //: -1073741824 654514f5e3Sopenharmony_ci 664514f5e3Sopenharmony_ci// Check with single float param 674514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 684514f5e3Sopenharmony_ciprint(Math.fround(1.9e80)); //: Infinity 694514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 704514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#printZero@builtinMathFround caller function name: func_main_0@builtinMathFround 714514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:#*#printZero@builtinMathFround 724514f5e3Sopenharmony_ciprintZero(Math.fround(2.5)); //: 2.5 734514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 744514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#printZero@builtinMathFround caller function name: func_main_0@builtinMathFround 754514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:#*#printZero@builtinMathFround 764514f5e3Sopenharmony_ciprintZero(Math.fround(1.5)); //: 1.5 774514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 784514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#printZero@builtinMathFround caller function name: func_main_0@builtinMathFround 794514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:#*#printZero@builtinMathFround 804514f5e3Sopenharmony_ciprintZero(Math.fround(0.5)); //: 0.5 814514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 824514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#printZero@builtinMathFround caller function name: func_main_0@builtinMathFround 834514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:#*#printZero@builtinMathFround 844514f5e3Sopenharmony_ciprintZero(Math.fround(0.2)); //: 0.20000000298023224 854514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 864514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#printZero@builtinMathFround caller function name: func_main_0@builtinMathFround 874514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:#*#printZero@builtinMathFround 884514f5e3Sopenharmony_ciprintZero(Math.fround(-0)); //: -0 894514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 904514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#printZero@builtinMathFround caller function name: func_main_0@builtinMathFround 914514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:#*#printZero@builtinMathFround 924514f5e3Sopenharmony_ciprintZero(Math.fround(-1.9e-80)); //: -0 934514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 944514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:#*#printZero@builtinMathFround 954514f5e3Sopenharmony_ciprintZero(Math.fround(-0.1)); //: -0.10000000149011612 964514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 974514f5e3Sopenharmony_ciprint(Math.fround(-0.5)); //: -0.5 984514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 994514f5e3Sopenharmony_ciprint(Math.fround(-1.5)); //: -1.5 1004514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 1014514f5e3Sopenharmony_ciprint(Math.fround(-2.1)); //: -2.0999999046325684 1024514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 1034514f5e3Sopenharmony_ciprint(Math.fround(-2.49)); //: -2.490000009536743 1044514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 1054514f5e3Sopenharmony_ciprint(Math.fround(-2.5)); //: -2.5 1064514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 1074514f5e3Sopenharmony_ciprint(Math.fround(-2.7)); //: -2.700000047683716 1084514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 1094514f5e3Sopenharmony_ciprint(Math.fround(-1.9e80)); //: -Infinity 1104514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 1114514f5e3Sopenharmony_ciprint(Math.fround(1.9e-80)); //: 0 1124514f5e3Sopenharmony_ci 1134514f5e3Sopenharmony_ci// Check with special float params 1144514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 1154514f5e3Sopenharmony_ciprint(Math.fround(Infinity)); //: Infinity 1164514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 1174514f5e3Sopenharmony_ciprint(Math.fround(-Infinity)); //: -Infinity 1184514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 1194514f5e3Sopenharmony_ciprint(Math.fround(NaN)); //: NaN 1204514f5e3Sopenharmony_ci 1214514f5e3Sopenharmony_ci// Check with 2 params 1224514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 1234514f5e3Sopenharmony_ciprint(Math.fround(3, 0)); //: 3 1244514f5e3Sopenharmony_ci 1254514f5e3Sopenharmony_ci// Check with 3 params 1264514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 1274514f5e3Sopenharmony_ciprint(Math.fround(-3.5, 0, 0)); //: -3.5 1284514f5e3Sopenharmony_ci 1294514f5e3Sopenharmony_ci// Check with 4 params 1304514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 1314514f5e3Sopenharmony_ciprint(Math.fround(4.1, 0, 0, 0)); //: 4.099999904632568 1324514f5e3Sopenharmony_ci 1334514f5e3Sopenharmony_ci// Check with 5 params 1344514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 1354514f5e3Sopenharmony_ciprint(Math.fround(-4.1, 0, 0, 0, 0)); //: -4.099999904632568 1364514f5e3Sopenharmony_ci 1374514f5e3Sopenharmony_ci// Replace standard builtin 1384514f5e3Sopenharmony_cilet true_fround = Math.fround 1394514f5e3Sopenharmony_ciMath.fround = replace 1404514f5e3Sopenharmony_ci 1414514f5e3Sopenharmony_ci// no deopt 1424514f5e3Sopenharmony_ciprint(Math.fround(-1.001)); //: -1.001 1434514f5e3Sopenharmony_ciMath.fround = true_fround 1444514f5e3Sopenharmony_ci 1454514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:#*#doFround@builtinMathFround 1464514f5e3Sopenharmony_ciprintFround(12.3); //: 12.300000190734863 1474514f5e3Sopenharmony_ci// Call standard builtin with non-number param 1484514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:#*#doFround@builtinMathFround 1494514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber1 1504514f5e3Sopenharmony_ciprintFround("abc"); //: NaN 1514514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:#*#doFround@builtinMathFround 1524514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber1 1534514f5e3Sopenharmony_ciprintFround("-12.9"); //: -12.899999618530273 1544514f5e3Sopenharmony_ci 1554514f5e3Sopenharmony_ciif (ArkTools.isAOTCompiled(printFround)) { 1564514f5e3Sopenharmony_ci // Replace standard builtin after call to standard builtin was profiled 1574514f5e3Sopenharmony_ci Math.fround = replace 1584514f5e3Sopenharmony_ci} 1594514f5e3Sopenharmony_ciprintFround(-12.2); //pgo: -12.199999809265137 1604514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotCallTarget1 1614514f5e3Sopenharmony_ci//aot: -12.2 1624514f5e3Sopenharmony_ci 1634514f5e3Sopenharmony_ciprintFround("abc"); //pgo: NaN 1644514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotCallTarget1 1654514f5e3Sopenharmony_ci//aot: abc 1664514f5e3Sopenharmony_ci 1674514f5e3Sopenharmony_ciMath.fround = true_fround 1684514f5e3Sopenharmony_ci 1694514f5e3Sopenharmony_ci// Check IR correctness inside try-block 1704514f5e3Sopenharmony_citry { 1714514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Math.fround, caller function name:#*#doFround@builtinMathFround 1724514f5e3Sopenharmony_ci printFround(0.3) //: 0.30000001192092896 1734514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Math.fround, caller function name:#*#doFround@builtinMathFround 1744514f5e3Sopenharmony_ci printFround(-12); //: -12 1754514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Math.fround, caller function name:#*#doFround@builtinMathFround 1764514f5e3Sopenharmony_ci //aot: [trace] Check Type: NotNumber1 1774514f5e3Sopenharmony_ci printFround("abc"); //: NaN 1784514f5e3Sopenharmony_ci} catch (e) { 1794514f5e3Sopenharmony_ci} 1804514f5e3Sopenharmony_ci 1814514f5e3Sopenharmony_cilet obj = { 1824514f5e3Sopenharmony_ci valueOf: () => { return -22.5; } 1834514f5e3Sopenharmony_ci}; 1844514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.fround, caller function name:func_main_0@builtinMathFround 1854514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber1 1864514f5e3Sopenharmony_ciprint(Math.fround(obj)); //: -22.5 187