diff --git a/TUTORIAL.md b/TUTORIAL.md index e8820da585..616541fe22 100644 --- a/TUTORIAL.md +++ b/TUTORIAL.md @@ -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` | diff --git a/compiler/builtins/docs/Num.roc b/compiler/builtins/docs/Num.roc index 2f45e22600..76b7c4f52b 100644 --- a/compiler/builtins/docs/Num.roc +++ b/compiler/builtins/docs/Num.roc @@ -47,7 +47,7 @@ interface Num compare, cos, div, - divFloor, + divTrunc, floor, intCast, isEven, @@ -781,7 +781,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! @@ -791,18 +791,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. ## diff --git a/compiler/builtins/roc/Num.roc b/compiler/builtins/roc/Num.roc index 3038842caa..d7a4daaa8b 100644 --- a/compiler/builtins/roc/Num.roc +++ b/compiler/builtins/roc/Num.roc @@ -99,8 +99,8 @@ interface Num bytesToU32, divCeil, divCeilChecked, - divFloor, - divFloorChecked, + divTrunc, + divTruncChecked, toStr, isMultipleOf, minI8, @@ -237,8 +237,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 ]* diff --git a/compiler/builtins/src/std.rs b/compiler/builtins/src/std.rs index cc0fd16ef0..68bab5db31 100644 --- a/compiler/builtins/src/std.rs +++ b/compiler/builtins/src/std.rs @@ -316,16 +316,16 @@ pub fn types() -> MutMap { 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())), ); diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index d194966b8b..a6f9e13957 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -196,8 +196,8 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option 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, @@ -4369,13 +4369,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(); diff --git a/compiler/can/src/operator.rs b/compiler/can/src/operator.rs index 6bbb3d23b9..0386408b47 100644 --- a/compiler/can/src/operator.rs +++ b/compiler/can/src/operator.rs @@ -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"), diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 5be160e1d8..e5b12d8b0a 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -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" diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 678175cbb5..af6512cc1c 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -3402,11 +3402,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", @@ -3414,11 +3414,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 ]*", diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index 62f9f21eb4..0b1fa649f6 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -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 "# diff --git a/compiler/test_mono/src/tests.rs b/compiler/test_mono/src/tests.rs index bba051e6b6..e64a36f72e 100644 --- a/compiler/test_mono/src/tests.rs +++ b/compiler/test_mono/src/tests.rs @@ -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 "# diff --git a/examples/false-interpreter/False.roc b/examples/false-interpreter/False.roc index f8306e7d8d..537d794a18 100644 --- a/examples/false-interpreter/False.roc +++ b/examples/false-interpreter/False.roc @@ -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)) ) diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index d0360ac569..53b692266c 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -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 ]*", ); } diff --git a/roc-for-elm-programmers.md b/roc-for-elm-programmers.md index 204ad125a9..ced8f5811e 100644 --- a/roc-for-elm-programmers.md +++ b/roc-for-elm-programmers.md @@ -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` |