Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions math/round.jule
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn Round(n: f64): f64 {
if n >= 0 {
return f64(int(n + 0.5))
}
return f64(int(n - 0.5))
}
18 changes: 18 additions & 0 deletions math/round_test.jule
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#build test

use "std/testing"

#test
fn testRound(t: &testing::T) {
t.Assert(Round(12.2) == 12, "12.2 should round to 12")
t.Assert(Round(12.5) == 13, "12.5 should round to 13")
t.Assert(Round(12.8) == 13, "12.8 should round to 13")
t.Assert(Round(12.0) == 12, "12.0 should round to 12")
t.Assert(Round(-12.2) == -12, "-12.2 should round to -12")
t.Assert(Round(-12.5) == -13, "-12.5 should round to -13")
t.Assert(Round(-12.8) == -13, "-12.8 should round to -13")
t.Assert(Round(0.49) == 0, "0.49 should round to 0")
t.Assert(Round(0.5) == 1, "0.5 should round to 1")
t.Assert(Round(-0.49) == 0, "-0.49 should round to 0")
t.Assert(Round(-0.5) == -1, "-0.5 should round to -1")
}
Loading