Skip to content

Commit

Permalink
fix(std): math round (amber-lang#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mte90 committed Aug 31, 2024
1 parent 0a2a8f9 commit a701b52
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/std/math.ab
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ pub fun sum(list: [Num]): Num {
/// Returns the number rounded to the nearest integer
#[allow_absurd_cast]
pub fun round(number: Num): Num {
return unsafe $LC_ALL=C printf "%0.f" "{number}"$ as Num
if number > 0 {
return unsafe $echo "({number}+0.5)/1" | bc$ as Num
}

return unsafe $echo "({number}-0.5)/1" | bc$ as Num
}

/// Returns the largest integer less than or equal to the number
Expand Down

0 comments on commit a701b52

Please sign in to comment.