• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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    assert b == -10.0;
21
22    a = -a;
23    assert a == -10.0;
24
25    let c = +a;
26    assert c == -10.0;
27    assert +c == -10.0;
28    assert -c == 10.0;
29  }
30
31  {
32    let a: int = 20;
33    let b = -a;
34    assert b == -20;
35
36    a = -a;
37    assert a == -20;
38
39    let c = +a;
40    assert c == -20;
41    assert +c == -20;
42    assert -c == 20;
43  }
44
45  {
46    let a: Double = new Double(30.0);
47    let b = -a;
48    assert b == -30.0;
49
50    a = -a;
51    assert a == -30.0;
52    assert a.doubleValue() == -30.0;
53
54    let c = +a;
55    assert c == -30.0;
56    assert +c == -30.0;
57    assert -c == 30.0;
58  }
59
60  {
61    let a: Int = new Int(40);
62    let b = -a;
63    assert b == -40;
64
65    a = -a;
66    assert a == -40;
67    assert a.intValue() == -40;
68
69    let c = +a;
70    assert c == -40;
71    assert +c == -40;
72    assert -c == 40;
73  }
74
75  {
76    let a = -new Int(50);
77    assert a == -50;
78
79    let b = -a;
80    assert b == 50;
81
82    let c = +a;
83    assert c == -50;
84    assert +c == -50;
85    assert -c == 50;
86  }
87
88  {
89    let a = +new Double(60.0);
90    assert a == 60.0;
91
92    let b = -a;
93    assert b == -60.0;
94
95    let c = +a;
96    assert c == 60.0;
97    assert +c == 60.0;
98    assert -c == -60.0;
99  }
100}
101