Skip to content

Commit 41e012a

Browse files
authored
Fix toRadixString on math.minInt (#1656)
Closes #1655
1 parent aa01241 commit 41e012a

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

pkl-core/src/main/java/org/pkl/core/stdlib/base/IntNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
2+
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -190,7 +190,7 @@ public abstract static class toRadixString extends ExternalMethod1Node {
190190
@Specialization
191191
@TruffleBoundary
192192
protected String eval(long self, long radix) {
193-
return (self < 0 ? "-" : "") + Long.toString(Math.abs(self), (int) radix);
193+
return Long.toString(self, (int) radix);
194194
}
195195
}
196196

pkl-core/src/test/files/LanguageSnippetTests/input/api/int.pkl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
amends "../snippetTest.pkl"
22

3+
import "pkl:math"
4+
35
facts {
46
["isEven"] {
57
(-124).isEven
@@ -92,7 +94,7 @@ examples {
9294
0.floor
9395
(-0).floor
9496
}
95-
97+
9698
["toRadixString()"] {
9799
123.toRadixString(16)
98100
123.toRadixString(2)
@@ -101,15 +103,17 @@ examples {
101103
(-123).toRadixString(16)
102104
(-123).toRadixString(2)
103105
(-123).toRadixString(33)
104-
106+
105107
0.toRadixString(16)
106108
0.toRadixString(2)
107109
0.toRadixString(33)
108-
110+
109111
(-0).toRadixString(16)
110112
(-0).toRadixString(2)
111113
(-0).toRadixString(33)
112-
114+
115+
math.minInt.toRadixString(10)
116+
113117
module.catch(() -> (-123).toRadixString(-1))
114118
module.catch(() -> (-123).toRadixString(64))
115119
}
@@ -159,7 +163,7 @@ examples {
159163
(-123).toFixed(2)
160164
0.toFixed(3)
161165
(-0).toFixed(4)
162-
166+
163167
123456789.toFixed(1)
164168
123456789.toFixed(2)
165169
123456789.toFixed(3)

pkl-core/src/test/files/LanguageSnippetTests/output/api/int.pcf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ examples {
9090
"0"
9191
"0"
9292
"0"
93+
"-9223372036854775808"
9394
"Type constraint `this.isBetween(2, 36)` violated. Value: -1"
9495
"Type constraint `this.isBetween(2, 36)` violated. Value: 64"
9596
}

0 commit comments

Comments
 (0)