1/* 2 * Copyright (c) 2023-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 main(): void { 17 { 18 let a: double = 10.0; 19 let b = -a; 20 assertEQ(b, -10.0) 21 22 a = -a; 23 assertEQ(a, -10.0) 24 25 let c = +a; 26 assertEQ(c, -10.0) 27 assertEQ(+c, -10.0) 28 assertEQ(-c, 10.0) 29 } 30 31 { 32 let a: int = 20; 33 let b = -a; 34 assertEQ(b, -20) 35 36 a = -a; 37 assertEQ(a, -20) 38 39 let c = +a; 40 assertEQ(c, -20) 41 assertEQ(+c, -20) 42 assertEQ(-c, 20) 43 } 44 45 { 46 let a: Double = new Double(30.0); 47 let b = -a; 48 assertEQ(b, -30.0) 49 50 a = -a; 51 assertEQ(a, -30.0) 52 assertEQ(a.toDouble(), -30.0) 53 54 let c = +a; 55 assertEQ(c, -30.0) 56 assertEQ(+c, -30.0) 57 assertEQ(-c, 30.0) 58 } 59 60 { 61 let a: Int = new Int(40); 62 let b = -a; 63 assertEQ(b, -40) 64 65 a = -a; 66 assertEQ(a, -40) 67 assertEQ(a.toInt(), -40) 68 69 let c = +a; 70 assertEQ(c, -40) 71 assertEQ(+c, -40) 72 assertEQ(-c, 40) 73 } 74 75 { 76 let a = -new Int(50); 77 assertEQ(a, -50) 78 79 let b = -a; 80 assertEQ(b, 50) 81 82 let c = +a; 83 assertEQ(c, -50) 84 assertEQ(+c, -50) 85 assertEQ(-c, 50) 86 } 87 88 { 89 let a = +new Double(60.0); 90 assertEQ(a, 60.0) 91 92 let b = -a; 93 assertEQ(b, -60.0) 94 95 let c = +a; 96 assertEQ(c, 60.0) 97 assertEQ(+c, 60.0) 98 assertEQ(-c, -60.0) 99 } 100 101 { 102 let a = -(-1); 103 assertEQ(a, 1); 104 105 let b = -(1); 106 assertEQ(b, -1); 107 108 let c = - -1; 109 assertEQ(c, 1); 110 111 let d = +(1); 112 assertEQ(d, 1); 113 114 let e = +(-1); 115 assertEQ(e, -1); 116 117 let f = + -1; 118 assertEQ(f, -1); 119 } 120} 121