1/* 2 * Copyright (c) 2024-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 joinSpread(first: double, ...rest: double[]): double[] { 17 let res = new double[rest.length + 1] 18 let i = 0 19 res[i] = first 20 i++ 21 for (let it of rest) { 22 res[i] = it 23 i++ 24 } 25 return res; 26} 27 28function bar(a: int, b: int, c: int) { 29 let res = joinSpread(a, b, c) 30 assertEQ(res.length, 3) 31 assertEQ(res[0], a) 32 assertEQ(res[1], b) 33 assertEQ(res[2], c) 34} 35 36function first(...values: number[]): number { 37 return values[0] 38} 39 40function foo(a: int, b: int) { 41 return first(a, b) 42} 43 44function main(): void { 45 46 let f: float = 1000000001.044 47 let f_i = f as int 48 let f_l = f as long 49 assertEQ(f_l, 1000000000) 50 assertEQ(f_i, 1000000000) 51 52 let d: double = 1000000001.044 53 let d_i = d as int 54 let d_l = d as long 55 assertEQ(d_l, 1000000001) 56 assertEQ(d_i, 1000000001) 57 58 let f2: float= 10001.044 59 let f_i2 = f2 as int 60 let f_l2 = f2 as long 61 assertEQ(f_l2, 10001) 62 assertEQ(f_i2, 10001) 63 64 let i: int = 2147483647 65 let i_f = i as float 66 let i_d = i as double 67 assertEQ(i_f, 2147483600) 68 assertEQ(i_d, 2147483647) 69 70 let i2: int = 1073741824 71 let i_f2 = i2 as float 72 let i_d2 = i2 as double 73 assertEQ(i_f2, 1073741824) 74 assertEQ(i_d2, 1073741824) 75 76 let l: long= 1073741824 77 let l_f = l as float 78 let d_f = l as double 79 assertEQ(l_f, 1073741824) 80 assertEQ(d_f, 1073741824) 81 82 let l2: int = 2147483647 83 let l_f2 = l2 as float 84 let d_f2 = l2 as double 85 assertEQ(l_f2, 2147483600) 86 assertEQ(d_f2, 2147483647) 87 88 bar(314, 27182, 2) 89 assertEQ(foo(2, 1), 2) 90} 91