Skip to content

Commit

Permalink
Fix toString() of 0 for all radix values (#713)
Browse files Browse the repository at this point in the history
  • Loading branch information
ainsleyrutterford authored Dec 1, 2024
1 parent acf47ed commit 91c1683
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libs/llrt_numbers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ pub fn i64_to_base_n(number: i64, radix: u8) -> String {

#[inline(always)]
fn internal_i64_to_base_n(buf: &mut [u8], number: i64, radix: u8) -> usize {
if number == 0 {
buf[BUF_SIZE - 1] = DIGITS[0];
return BUF_SIZE - 1;
}

let mut n = number;
let mut index = BUF_SIZE;

Expand Down Expand Up @@ -295,6 +300,9 @@ mod test {
}

// Test i64_to_base_n
let base_36 = i64_to_base_n(0, 36);
assert_eq!("0", base_36);

let base_36 = i64_to_base_n(123456789, 36);
assert_eq!("21i3v9", base_36);

Expand Down

0 comments on commit 91c1683

Please sign in to comment.