Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: renamed modulus to modulo; updated modulo operator defintion #583

Merged
merged 14 commits into from
Dec 19, 2023
Merged
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
55 changes: 54 additions & 1 deletion extensions/functions_arithmetic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -285,31 +285,84 @@ scalar_functions:
return: fp64
-
name: "modulus"
description: "Get the remainder when dividing one value by another."
description: >
Calculate the remainder (r) when dividing dividend (x) by divisor (y).

In mathematics, many conventions for the modulus (mod) operation exists. The result of a mod operation
depends on the software implementation and underlying hardware. Substrait is a format for describing compute
operations on structured data and designed for interoperability. Therefore the user is responsible for determining
a definition of division as defined by the quotient (q).

The following basic conditions of division are satisfied:
(1) q ∈ ℤ (the quotient is an integer)
(2) x = y * q + r (division rule)
(3) abs(r) < abs(y)
where q is the quotient.

The `division_type` option determines the mathematical definition of quotient to use in the above definition of
division.

When `division_type`=TRUNCATE, q = trunc(x/y).
When `division_type`=FLOOR, q = floor(x/y).

In the cases of TRUNCATE and FLOOR division: remainder r = x - round_func(x/y)

The `on_domain_error` option governs behavior in cases where y is 0, y is +/-inf, or x is +/-inf. In these cases
the mod is undefined.
The `overflow` option governs behavior when integer overflow occurs.
If x and y are both 0 or both +/-infinity, behavior will be governed by `on_domain_error`.
impls:
- args:
- name: x
value: i8
- name: y
value: i8
options:
division_type:
values: [ TRUNCATE, FLOOR ]
overflow:
values: [ SILENT, SATURATE, ERROR ]
westonpace marked this conversation as resolved.
Show resolved Hide resolved
on_domain_error:
values: [ "NULL", ERROR ]
return: i8
- args:
- name: x
value: i16
- name: y
value: i16
options:
division_type:
values: [ TRUNCATE, FLOOR ]
overflow:
values: [ SILENT, SATURATE, ERROR ]
on_domain_error:
values: [ "NULL", ERROR ]
return: i16
- args:
- name: x
value: i32
- name: y
value: i32
options:
division_type:
values: [ TRUNCATE, FLOOR ]
overflow:
values: [ SILENT, SATURATE, ERROR ]
on_domain_error:
values: [ "NULL", ERROR ]
return: i32
- args:
- name: x
value: i64
- name: y
value: i64
options:
division_type:
values: [ TRUNCATE, FLOOR ]
overflow:
values: [ SILENT, SATURATE, ERROR ]
on_domain_error:
values: [ "NULL", ERROR ]
return: i64
-
name: "power"
Expand Down
Loading