Fix toRadixString on math.minInt (#1656)

Closes #1655
This commit is contained in:
Daniel Chao
2026-06-05 11:27:03 -07:00
committed by GitHub
parent aa01241068
commit 41e012a0f0
3 changed files with 12 additions and 7 deletions
@@ -1,5 +1,5 @@
/* /*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. * Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -190,7 +190,7 @@ public final class IntNodes {
@Specialization @Specialization
@TruffleBoundary @TruffleBoundary
protected String eval(long self, long radix) { protected String eval(long self, long radix) {
return (self < 0 ? "-" : "") + Long.toString(Math.abs(self), (int) radix); return Long.toString(self, (int) radix);
} }
} }
@@ -1,5 +1,7 @@
amends "../snippetTest.pkl" amends "../snippetTest.pkl"
import "pkl:math"
facts { facts {
["isEven"] { ["isEven"] {
(-124).isEven (-124).isEven
@@ -110,6 +112,8 @@ examples {
(-0).toRadixString(2) (-0).toRadixString(2)
(-0).toRadixString(33) (-0).toRadixString(33)
math.minInt.toRadixString(10)
module.catch(() -> (-123).toRadixString(-1)) module.catch(() -> (-123).toRadixString(-1))
module.catch(() -> (-123).toRadixString(64)) module.catch(() -> (-123).toRadixString(64))
} }
@@ -90,6 +90,7 @@ examples {
"0" "0"
"0" "0"
"0" "0"
"-9223372036854775808"
"Type constraint `this.isBetween(2, 36)` violated. Value: -1" "Type constraint `this.isBetween(2, 36)` violated. Value: -1"
"Type constraint `this.isBetween(2, 36)` violated. Value: 64" "Type constraint `this.isBetween(2, 36)` violated. Value: 64"
} }