1/*
2 * Copyright (c) 2024 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
16declare function print(arg:any):string;
17function replace(a : number)
18{
19    return a;
20}
21
22// Check without params
23//aot: [trace] aot inline builtin: Math.sqrt, caller function name:func_main_0@builtinMathSqrt
24print(Math.sqrt()); //: NaN
25
26// Check multiple params
27//aot: [trace] aot inline builtin: Math.sqrt, caller function name:func_main_0@builtinMathSqrt
28print(Math.sqrt(2, -3, 4)); //: 1.4142135623730951
29
30//aot: [trace] aot inline builtin: Math.sqrt, caller function name:func_main_0@builtinMathSqrt
31print(Math.sqrt(2, -3, -4)); //: 1.4142135623730951
32
33//aot: [trace] aot inline builtin: Math.sqrt, caller function name:func_main_0@builtinMathSqrt
34print(Math.sqrt(-2, -3, -4)); //: NaN
35
36//aot: [trace] aot inline builtin: Math.sqrt, caller function name:func_main_0@builtinMathSqrt
37print(Math.sqrt(-2, 3, 4, 5)); //: NaN
38
39// Check with single param
40//aot: [trace] aot inline builtin: Math.sqrt, caller function name:func_main_0@builtinMathSqrt
41print(Math.sqrt(NaN)); //: NaN
42//aot: [trace] aot inline builtin: Math.sqrt, caller function name:func_main_0@builtinMathSqrt
43print(Math.sqrt(0)); //: 0
44//aot: [trace] aot inline builtin: Math.sqrt, caller function name:func_main_0@builtinMathSqrt
45print(Math.sqrt(-156)); //: NaN
46//aot: [trace] aot inline builtin: Math.sqrt, caller function name:func_main_0@builtinMathSqrt
47print(Math.sqrt(1)); //: 1
48//aot: [trace] aot inline builtin: Math.sqrt, caller function name:func_main_0@builtinMathSqrt
49print(Math.sqrt(10)); //: 3.1622776601683795
50//aot: [trace] aot inline builtin: Math.sqrt, caller function name:func_main_0@builtinMathSqrt
51print(1 / Math.sqrt(-0)); //: -Infinity
52
53// Check Infinity
54//aot: [trace] aot inline builtin: Math.sqrt, caller function name:func_main_0@builtinMathSqrt
55print(Math.sqrt(Infinity)); //: Infinity
56//aot: [trace] aot inline builtin: Math.sqrt, caller function name:func_main_0@builtinMathSqrt
57print(Math.sqrt(-Infinity)); //: NaN
58
59// Replace standart builtin
60let true_sqrt = Math.sqrt
61Math.sqrt = replace
62print(Math.sqrt(111)); //: 111
63
64Math.sqrt = true_sqrt
65//aot: [trace] aot inline builtin: Math.sqrt, caller function name:func_main_0@builtinMathSqrt
66print(Math.sqrt(Math.PI)); //: 1.7724538509055159
67//aot: [trace] aot inline builtin: Math.sqrt, caller function name:func_main_0@builtinMathSqrt
68//aot: [trace] Check Type: NotNumber1
69print(Math.sqrt("9")); //: 3
70
71