Skip to content

Commit

Permalink
std::math::big: fix signed integer conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Mar 2, 2024
1 parent b252afc commit 963939c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion std/math/big/int.jule
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ impl Int {
}
let x = i64(u64_from_bits(self.nat.bits))
if self.neg {
ret i64.MIN + x
if x == 0 {
ret i64.MIN
}
ret -x
}
ret x
}
Expand Down
5 changes: 4 additions & 1 deletion std/math/big/nat.jule
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Nat {

// Returns Nat that initialized by integer value.
// T can only be signed or unsigned integer types.
pub static fn new[T](i: T): Nat {
pub static fn new[T](mut i: T): Nat {
match type T {
| Nat:
ret i
Expand Down Expand Up @@ -53,6 +53,9 @@ impl Nat {
|:
panic("std::math::big: Nat.new[T]: T is should be signed or unsigned integer type")
}
if i < 0 {
i = -i
}
for j in nat.bits {
nat.bits[j] = bit((i >> j) & 0b1)
}
Expand Down

0 comments on commit 963939c

Please sign in to comment.