rename divFloor to divTrunc

This commit is contained in:
Kevin Gillette 2022-04-18 02:33:31 -06:00
parent 000ec79106
commit 6a3fd3a607
No known key found for this signature in database
GPG key ID: 9009F701BBC0D562
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.sub a b` |
| `a * b` | `Num.mul a b` | | `a * b` | `Num.mul a b` |
| `a / b` | `Num.div 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.pow a b` |
| `a % b` | `Num.rem a b` | | `a % b` | `Num.rem a b` |
| `a %% b` | `Num.mod a b` | | `a %% b` | `Num.mod a b` |

View file

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

View file

@ -99,8 +99,8 @@ interface Num
bytesToU32, bytesToU32,
divCeil, divCeil,
divCeilChecked, divCeilChecked,
divFloor, divTrunc,
divFloorChecked, divTruncChecked,
toStr, toStr,
isMultipleOf, isMultipleOf,
minI8, minI8,
@ -237,8 +237,8 @@ divChecked : Float a, Float a -> Result (Float a) [ DivByZero ]*
divCeil : Int a, Int a -> Int a divCeil : Int a, Int a -> Int a
divCeilChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* divCeilChecked : Int a, Int a -> Result (Int a) [ DivByZero ]*
divFloor : Int a, Int a -> Int a divTrunc : Int a, Int a -> Int a
divFloorChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* divTruncChecked : Int a, Int a -> Result (Int a) [ DivByZero ]*
# mod : Float a, Float a -> Result (Float a) [ DivByZero ]* # mod : Float a, Float a -> Result (Float a) [ DivByZero ]*
rem : Int a, Int a -> Result (Int 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), Box::new(SolvedType::Wildcard),
); );
// divFloor : Int a, Int a -> Int a // divTrunc : Int a, Int a -> Int a
add_top_level_function_type!( add_top_level_function_type!(
Symbol::NUM_DIV_FLOOR, Symbol::NUM_DIV_TRUNC,
vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))],
Box::new(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!( add_top_level_function_type!(
Symbol::NUM_DIV_FLOOR_CHECKED, Symbol::NUM_DIV_TRUNC_CHECKED,
vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))],
Box::new(result_type(int_type(flex(TVAR1)), div_by_zero.clone())), Box::new(result_type(int_type(flex(TVAR1)), div_by_zero.clone())),
); );

View file

@ -196,8 +196,8 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option<Def>
NUM_TAN => num_tan, NUM_TAN => num_tan,
NUM_DIV_FLOAT => num_div_float, NUM_DIV_FLOAT => num_div_float,
NUM_DIV_FLOAT_CHECKED => num_div_float_checked, NUM_DIV_FLOAT_CHECKED => num_div_float_checked,
NUM_DIV_FLOOR => num_div_floor, NUM_DIV_TRUNC => num_div_trunc,
NUM_DIV_FLOOR_CHECKED => num_div_floor_checked, NUM_DIV_TRUNC_CHECKED => num_div_trunc_checked,
NUM_DIV_CEIL => num_div_ceil, NUM_DIV_CEIL => num_div_ceil,
NUM_DIV_CEIL_CHECKED => num_div_ceil_checked, NUM_DIV_CEIL_CHECKED => num_div_ceil_checked,
NUM_ABS => num_abs, 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 /// Num.divTrunc : Int a, Int a -> Int a
fn num_div_floor(symbol: Symbol, var_store: &mut VarStore) -> Def { fn num_div_trunc(symbol: Symbol, var_store: &mut VarStore) -> Def {
num_binop(symbol, var_store, LowLevel::NumDivUnchecked) num_binop(symbol, var_store, LowLevel::NumDivUnchecked)
} }
/// Num.divFloorChecked : Int a , Int a -> Result (Int a) [ DivByZero ]* /// Num.divTruncChecked : Int a , Int a -> Result (Int a) [ DivByZero ]*
fn num_div_floor_checked(symbol: Symbol, var_store: &mut VarStore) -> Def { fn num_div_trunc_checked(symbol: Symbol, var_store: &mut VarStore) -> Def {
let bool_var = var_store.fresh(); let bool_var = var_store.fresh();
let num_var = var_store.fresh(); let num_var = var_store.fresh();
let unbound_zero_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"), Caret => (ModuleName::NUM, "pow"),
Star => (ModuleName::NUM, "mul"), Star => (ModuleName::NUM, "mul"),
Slash => (ModuleName::NUM, "div"), Slash => (ModuleName::NUM, "div"),
DoubleSlash => (ModuleName::NUM, "divFloor"), DoubleSlash => (ModuleName::NUM, "divTrunc"),
Percent => (ModuleName::NUM, "rem"), Percent => (ModuleName::NUM, "rem"),
DoublePercent => (ModuleName::NUM, "mod"), DoublePercent => (ModuleName::NUM, "mod"),
Plus => (ModuleName::NUM, "add"), Plus => (ModuleName::NUM, "add"),

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -62,14 +62,14 @@ fn num_rem() {
#[cfg(not(feature = "wasm"))] #[cfg(not(feature = "wasm"))]
#[test] #[test]
fn num_floor_division() { fn num_floor_division() {
expect_success("Num.divFloor 4 3", "1 : Int *"); expect_success("Num.divTrunc 4 3", "1 : Int *");
} }
#[cfg(not(feature = "wasm"))] #[cfg(not(feature = "wasm"))]
#[test] #[test]
fn num_floor_checked_division_success() { fn num_floor_checked_division_success() {
expect_success( expect_success(
"Num.divFloorChecked 4 3", "Num.divTruncChecked 4 3",
"Ok 1 : Result (Int *) [ DivByZero ]*", "Ok 1 : Result (Int *) [ DivByZero ]*",
); );
} }
@ -78,7 +78,7 @@ fn num_floor_checked_division_success() {
#[test] #[test]
fn num_floor_checked_division_divby_zero() { fn num_floor_checked_division_divby_zero() {
expect_success( expect_success(
"Num.divFloorChecked 4 0", "Num.divTruncChecked 4 0",
"Err DivByZero : Result (Int *) [ DivByZero ]*", "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.sub a b` |
| `a * b` | `Num.mul a b` | | `a * b` | `Num.mul a b` |
| `a / b` | `Num.div 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.pow a b` |
| `a % b` | `Num.rem a b` | | `a % b` | `Num.rem a b` |
| `a %% b` | `Num.mod a b` | | `a %% b` | `Num.mod a b` |