mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
round towards nearest
This commit is contained in:
parent
1d7acfb070
commit
ae23f6fdf4
|
@ -45,8 +45,14 @@ fn roll_dice_scaled(number_of_dice: u32, bits_per_dice: u32, width: u32) -> i32
|
||||||
|
|
||||||
let dice_around_zero = dice - current_mean;
|
let dice_around_zero = dice - current_mean;
|
||||||
|
|
||||||
|
fn divide_nearest(numerator: i32, denominator: i32) -> i32 {
|
||||||
dice_around_zero * width as i32 / current_width
|
if (numerator < 0) ^ (denominator < 0) {
|
||||||
|
(numerator - denominator / 2) / denominator
|
||||||
|
} else {
|
||||||
|
(numerator + denominator / 2) / denominator
|
||||||
|
}
|
||||||
|
}
|
||||||
|
divide_nearest(dice_around_zero * width as i32, current_width)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_roll(width: u32) -> i32 {
|
fn default_roll(width: u32) -> i32 {
|
||||||
|
|
Loading…
Reference in a new issue