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
22let len:number = 1;
23
24// Check without params
25len = Math.cos();
26//aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
27print(len); //: NaN
28
29// Check with single param
30len = Math.cos(0);
31//aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
32print(len); //: 1
33
34// Check with single not zero param
35len = Math.cos(Math.PI / 2);
36//aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
37print(len); //: 6.123233995736766e-17
38
39// Check with 2 params
40len = Math.cos(0, 0);
41//aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
42print(len); //: 1
43
44// Check with 3 params
45len = Math.cos(0, 0, 0);
46//aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
47print(len); //: 1
48
49// Check with 4 params
50len = Math.cos(0, 0, 0, 0);
51//aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
52print(len); //: 1
53
54// Check with 5 params
55len = Math.cos(0, 0, 0, 0, 0);
56//aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
57print(len); //: 1
58
59try {
60    //aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
61    print(Math.cos(0)) //: 1
62} catch(e) {}
63
64// Replace standart builtin
65let true_cos = Math.cos
66
67len = true_cos();
68//aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
69print(len); //: NaN
70
71// Check with single param
72len = true_cos(0);
73//aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
74print(len); //: 1
75
76// Check with single not zero param
77len = true_cos(Math.PI / 2);
78//aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
79print(len); //: 6.123233995736766e-17
80
81// Check with 2 params
82len = true_cos(0, 0);
83//aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
84print(len); //: 1
85
86// Check with 3 params
87len = true_cos(0, 0, 0);
88//aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
89print(len); //: 1
90
91// Check with 4 params
92len = true_cos(0, 0, 0, 0);
93//aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
94print(len); //: 1
95
96// Check with 5 params
97len = true_cos(0, 0, 0, 0, 0);
98//aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
99print(len); //: 1
100
101try {
102    //aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
103    print(true_cos(0)) //: 1
104} catch(e) {}
105
106Math.cos = replace
107len = Math.cos(111);
108print(len); //: 111
109
110// Call standart builtin with non-number param
111Math.cos = true_cos
112
113//aot: [trace] aot inline builtin: Math.cos, caller function name:func_main_0@builtinMathCos
114//aot: [trace] Check Type: NotNumber1
115len = Math.cos("0");
116print(len); //: 1
117
118len = Math.cos("0.5");
119print(len); //: 0.8775825618903728