Merge pull request #2888 from rtfeldman/divTrunc

rename divFloor to divTrunc
This commit is contained in:
Richard Feldman 2022-04-19 21:57:49 -04:00 committed by GitHub
commit 93677001ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 36 additions and 36 deletions

View File

@ -1941,7 +1941,7 @@ Here are various Roc expressions involving operators, and what they desugar to.
| `a - b` | `Num.sub a b` |
| `a * b` | `Num.mul a b` |
| `a / b` | `Num.div a b` |
| `a // b` | `Num.divFloor a b` |
| `a // b` | `Num.divTrunc a b` |
| `a ^ b` | `Num.pow a b` |
| `a % b` | `Num.rem a b` |
| `a %% b` | `Num.mod a b` |

View File

@ -47,7 +47,7 @@ interface Num
compare,
cos,
div,
divFloor,
divTrunc,
floor,
intCast,
isEven,
@ -779,7 +779,7 @@ toU128 : Int * -> U128
## there will be a loss of precision.
toDec : Num * -> Dec
## Divide two integers and #Num.round the resulut.
## Divide two integers, truncating the result towards zero.
##
## Division by zero is undefined in mathematics. As such, you should make
## sure never to pass zero as the denomaintor to this function!
@ -789,18 +789,18 @@ toDec : Num * -> Dec
## * In a development build, you'll get an assertion failure.
## * In an optimized build, the function will return 0.
##
## `a // b` is shorthand for `Num.divRound a b`.
## `a // b` is shorthand for `Num.divTrunc a b`.
##
## >>> 5 // 7
##
## >>> Num.divRound 5 7
## >>> Num.divTrunc 5 7
##
## >>> 8 // -3
##
## >>> Num.divRound 8 -3
## >>> Num.divTrunc 8 -3
##
## This is the same as the #// operator.
divRound : Int a, Int a -> Int a
divTrunc : Int a, Int a -> Int a
## Perform flooring modulo on two integers.
##

View File

@ -95,8 +95,8 @@ interface Num
bytesToU32,
divCeil,
divCeilChecked,
divFloor,
divFloorChecked,
divTrunc,
divTruncChecked,
toStr,
isMultipleOf,
minI8,
@ -246,8 +246,8 @@ divChecked : Float a, Float a -> Result (Float a) [ DivByZero ]*
divCeil : Int a, Int a -> Int a
divCeilChecked : Int a, Int a -> Result (Int a) [ DivByZero ]*
divFloor : Int a, Int a -> Int a
divFloorChecked : Int a, Int a -> Result (Int a) [ DivByZero ]*
divTrunc : Int a, Int a -> Int a
divTruncChecked : Int a, Int a -> Result (Int a) [ DivByZero ]*
# mod : Float a, Float a -> Result (Float a) [ DivByZero ]*
rem : Int a, Int a -> Result (Int a) [ DivByZero ]*

View File

@ -316,16 +316,16 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
Box::new(SolvedType::Wildcard),
);
// divFloor : Int a, Int a -> Int a
// divTrunc : Int a, Int a -> Int a
add_top_level_function_type!(
Symbol::NUM_DIV_FLOOR,
Symbol::NUM_DIV_TRUNC,
vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))],
Box::new(int_type(flex(TVAR1)))
);
// divFloorChecked : Int a, Int a -> Result (Int a) [ DivByZero ]*
// divTruncChecked : Int a, Int a -> Result (Int a) [ DivByZero ]*
add_top_level_function_type!(
Symbol::NUM_DIV_FLOOR_CHECKED,
Symbol::NUM_DIV_TRUNC_CHECKED,
vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))],
Box::new(result_type(int_type(flex(TVAR1)), div_by_zero.clone())),
);

View File

@ -197,8 +197,8 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option<Def>
NUM_TAN => num_tan,
NUM_DIV_FLOAT => num_div_float,
NUM_DIV_FLOAT_CHECKED => num_div_float_checked,
NUM_DIV_FLOOR => num_div_floor,
NUM_DIV_FLOOR_CHECKED => num_div_floor_checked,
NUM_DIV_TRUNC => num_div_trunc,
NUM_DIV_TRUNC_CHECKED => num_div_trunc_checked,
NUM_DIV_CEIL => num_div_ceil,
NUM_DIV_CEIL_CHECKED => num_div_ceil_checked,
NUM_ABS => num_abs,
@ -4257,13 +4257,13 @@ fn num_div_float_checked(symbol: Symbol, var_store: &mut VarStore) -> Def {
)
}
/// Num.divFloor : Int a, Int a -> Int a
fn num_div_floor(symbol: Symbol, var_store: &mut VarStore) -> Def {
/// Num.divTrunc : Int a, Int a -> Int a
fn num_div_trunc(symbol: Symbol, var_store: &mut VarStore) -> Def {
num_binop(symbol, var_store, LowLevel::NumDivUnchecked)
}
/// Num.divFloorChecked : Int a , Int a -> Result (Int a) [ DivByZero ]*
fn num_div_floor_checked(symbol: Symbol, var_store: &mut VarStore) -> Def {
/// Num.divTruncChecked : Int a , Int a -> Result (Int a) [ DivByZero ]*
fn num_div_trunc_checked(symbol: Symbol, var_store: &mut VarStore) -> Def {
let bool_var = var_store.fresh();
let num_var = var_store.fresh();
let unbound_zero_var = var_store.fresh();

View File

@ -423,7 +423,7 @@ fn binop_to_function(binop: BinOp) -> (&'static str, &'static str) {
Caret => (ModuleName::NUM, "pow"),
Star => (ModuleName::NUM, "mul"),
Slash => (ModuleName::NUM, "div"),
DoubleSlash => (ModuleName::NUM, "divFloor"),
DoubleSlash => (ModuleName::NUM, "divTrunc"),
Percent => (ModuleName::NUM, "rem"),
DoublePercent => (ModuleName::NUM, "mod"),
Plus => (ModuleName::NUM, "add"),

View File

@ -948,8 +948,8 @@ define_builtins! {
39 NUM_REM_CHECKED: "remChecked"
40 NUM_DIV_FLOAT: "div"
41 NUM_DIV_FLOAT_CHECKED: "divChecked"
42 NUM_DIV_FLOOR: "divFloor"
43 NUM_DIV_FLOOR_CHECKED: "divFloorChecked"
42 NUM_DIV_TRUNC: "divTrunc"
43 NUM_DIV_TRUNC_CHECKED: "divTruncChecked"
44 NUM_MOD_INT: "modInt"
45 NUM_MOD_INT_CHECKED: "modIntChecked"
46 NUM_MOD_FLOAT: "modFloat"

View File

@ -3404,11 +3404,11 @@ mod solve_expr {
}
#[test]
fn div_floor() {
fn div_trunc() {
infer_eq_without_problem(
indoc!(
r#"
Num.divFloor
Num.divTrunc
"#
),
"Int a, Int a -> Int a",
@ -3416,11 +3416,11 @@ mod solve_expr {
}
#[test]
fn div_floor_checked() {
fn div_trunc_checked() {
infer_eq_without_problem(
indoc!(
r#"
Num.divFloorChecked
Num.divTruncChecked
"#
),
"Int a, Int a -> Result (Int a) [ DivByZero ]*",

View File

@ -1050,7 +1050,7 @@ fn gen_div_checked_i64() {
assert_evals_to!(
indoc!(
r#"
when Num.divFloorChecked 1000 10 is
when Num.divTruncChecked 1000 10 is
Ok val -> val
Err _ -> -1
"#
@ -1066,7 +1066,7 @@ fn gen_div_checked_by_zero_i64() {
assert_evals_to!(
indoc!(
r#"
when Num.divFloorChecked 1000 0 is
when Num.divTruncChecked 1000 0 is
Err DivByZero -> 99
_ -> -24
"#

View File

@ -275,7 +275,7 @@ fn ir_round() {
#[mono_test]
fn ir_when_idiv() {
r#"
when Num.divFloorChecked 1000 10 is
when Num.divTruncChecked 1000 10 is
Ok val -> val
Err _ -> -1
"#

View File

@ -434,7 +434,7 @@ stepExecCtx = \ctx, char ->
(
(T popCtx1 numR) <- Result.after (popNumber ctx)
(T popCtx2 numL) <- Result.after (popNumber popCtx1)
res <- Result.after (Num.divFloorChecked numL numR)
res <- Result.after (Num.divTruncChecked numL numR)
Ok (Context.pushStack popCtx2 (Number res))
)

View File

@ -62,14 +62,14 @@ fn num_rem() {
#[cfg(not(feature = "wasm"))]
#[test]
fn num_floor_division() {
expect_success("Num.divFloor 4 3", "1 : Int *");
expect_success("Num.divTrunc 4 3", "1 : Int *");
}
#[cfg(not(feature = "wasm"))]
#[test]
fn num_floor_checked_division_success() {
expect_success(
"Num.divFloorChecked 4 3",
"Num.divTruncChecked 4 3",
"Ok 1 : Result (Int *) [ DivByZero ]*",
);
}
@ -78,7 +78,7 @@ fn num_floor_checked_division_success() {
#[test]
fn num_floor_checked_division_divby_zero() {
expect_success(
"Num.divFloorChecked 4 0",
"Num.divTruncChecked 4 0",
"Err DivByZero : Result (Int *) [ DivByZero ]*",
);
}

View File

@ -1294,7 +1294,7 @@ Here are various Roc expressions involving operators, and what they desugar to.
| `a - b` | `Num.sub a b` |
| `a * b` | `Num.mul a b` |
| `a / b` | `Num.div a b` |
| `a // b` | `Num.divFloor a b` |
| `a // b` | `Num.divTrunc a b` |
| `a ^ b` | `Num.pow a b` |
| `a % b` | `Num.rem a b` |
| `a %% b` | `Num.mod a b` |