Skip to content

Commit 1b3c10c

Browse files
committed
Simplify abs
1 parent bca1aaa commit 1b3c10c

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

builtin/lib.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,76 +62,76 @@ func Type(arg any) any {
6262
}
6363

6464
func Abs(x any) any {
65-
switch x.(type) {
65+
switch x := x.(type) {
6666
case float32:
67-
if x.(float32) < 0 {
68-
return -x.(float32)
67+
if x < 0 {
68+
return -x
6969
} else {
7070
return x
7171
}
7272
case float64:
73-
if x.(float64) < 0 {
74-
return -x.(float64)
73+
if x < 0 {
74+
return -x
7575
} else {
7676
return x
7777
}
7878
case int:
79-
if x.(int) < 0 {
80-
return -x.(int)
79+
if x < 0 {
80+
return -x
8181
} else {
8282
return x
8383
}
8484
case int8:
85-
if x.(int8) < 0 {
86-
return -x.(int8)
85+
if x < 0 {
86+
return -x
8787
} else {
8888
return x
8989
}
9090
case int16:
91-
if x.(int16) < 0 {
92-
return -x.(int16)
91+
if x < 0 {
92+
return -x
9393
} else {
9494
return x
9595
}
9696
case int32:
97-
if x.(int32) < 0 {
98-
return -x.(int32)
97+
if x < 0 {
98+
return -x
9999
} else {
100100
return x
101101
}
102102
case int64:
103-
if x.(int64) < 0 {
104-
return -x.(int64)
103+
if x < 0 {
104+
return -x
105105
} else {
106106
return x
107107
}
108108
case uint:
109-
if x.(uint) < 0 {
110-
return -x.(uint)
109+
if x < 0 {
110+
return -x
111111
} else {
112112
return x
113113
}
114114
case uint8:
115-
if x.(uint8) < 0 {
116-
return -x.(uint8)
115+
if x < 0 {
116+
return -x
117117
} else {
118118
return x
119119
}
120120
case uint16:
121-
if x.(uint16) < 0 {
122-
return -x.(uint16)
121+
if x < 0 {
122+
return -x
123123
} else {
124124
return x
125125
}
126126
case uint32:
127-
if x.(uint32) < 0 {
128-
return -x.(uint32)
127+
if x < 0 {
128+
return -x
129129
} else {
130130
return x
131131
}
132132
case uint64:
133-
if x.(uint64) < 0 {
134-
return -x.(uint64)
133+
if x < 0 {
134+
return -x
135135
} else {
136136
return x
137137
}

0 commit comments

Comments
 (0)