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 16 17function main(): void { 18 19let nan_byte = Infinity * 0 as byte 20let nan_short = Infinity * 0 as short 21let nan_long = Infinity * 0 as long 22let nan_char = Infinity * 0 as char 23let nan_int = Infinity * 0 as int 24let nan_float = Infinity * 0 as float 25let nan_double = Infinity * 0 as double 26let nan_byte2 = Infinity * 0 as byte 27 28assert(nan_byte == 0) 29assert(nan_int == 0) 30assert(nan_short == 0) 31assert(nan_long == 0) 32assert(nan_char == 0) 33assert(isNaN(nan_float)) 34assert(isNaN(nan_double)) 35assert(nan_byte2 == 0) 36 37let b1 = Infinity as byte // converted at compile time, as 'Infinity' is constant 38let b2: double = Infinity 39let b3 = b2 as byte // converted in runtime, as b2 isn't constant 40 41assert(b1 == -1) 42assert(b3 == -1) 43 44let l1 = Infinity as long 45let l2: double = Infinity 46let l3 = l2 as long 47let l4 = -Infinity as long 48 49assert(l1 == 9223372036854775807) 50assert(l3 == 9223372036854775807) 51assert(l4 == -9223372036854775808) 52 53let i1 = Infinity as int 54let i2: double = Infinity 55let i3 = i2 as int 56let i4 = -Infinity as int 57 58assert(i1 == 2147483647) 59assert(i3 == 2147483647) 60assert(i4 == -2147483648) 61 62let s1 = Infinity as short 63let s2: double = Infinity 64let s3 = s2 as short 65let s4 = -Infinity as short 66 67assert(s1 == -1) 68assert(s3 == -1) 69assert(s4 == 0) 70 71let c1 = Infinity as char 72let c2: double = Infinity 73let c3 = c2 as char 74let c4 = -Infinity as char 75 76assert(c1 == 65535) 77assert(c3 == 65535) 78assert(c4 == 0) 79 80let f1 = Infinity as float 81let f2: double = Infinity 82let f3 = f2 as float 83let f4 = -Infinity as float 84 85assert(f1 == Infinity) 86assert(f3 == Infinity) 87assert(f4 == -Infinity) 88 89let d1 = Infinity as double 90let d2: double = Infinity 91let d3 = d2 as double 92let d4 = -Infinity as double 93 94assert(d1 == Infinity) 95assert(d3 == Infinity) 96assert(d4 == -Infinity) 97} 98