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

feat: add options for behaviour when dividing by zero or calculating log zero #329

Merged
merged 3 commits into from
Sep 15, 2022

Conversation

thisisnic
Copy link
Contributor

This PR adds options which allow specification of behaviour when dividing by 0 or when trying to calculate log of 0. See discussion on #302 for more detail.

description: >
Divide x by y. In the case of integer division, partial values are truncated.
The `on_division_by_zero` option governs behaviour in cases where y is 0 and x is not 0.
The `on_domain_error` option governs behaviour for 0/0 and Inf/Inf etc.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is quite right?

Copy link
Contributor

@jvanstraten jvanstraten Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks fine to me, but cc @pitrou

ETA: actually, the order should probably be LIMIT, NAN, and then ERROR, because LIMIT makes the most sense. We should probably specify what LIMIT means, too (i.e. +/- infinity based on sign of numerator and signed zero denominator).

PS. I honestly can't tell if github actually added this comment when I first reviewed this because the UI was glitching all to hell, but it seems to be missing for me now, so... Please excuse me if this ends up being duplicated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, updated now!

@thisisnic thisisnic force-pushed the maths_special_cases branch 3 times, most recently from d79e06c to 6475119 Compare September 12, 2022 16:57
@@ -175,7 +175,10 @@ scalar_functions:
return: fp64
-
name: "divide"
description: "Divide one value by another. Partial values are truncated."
description: >
Divide x by y. In the case of integer division, partial values are truncated.
Copy link
Contributor

@pitrou pitrou Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we describe more precisely what "partial values are truncated" means? (truncated towards zero, or truncated towards minus infinity - i.e. floored?)
For example, what would be the result of 1 / -3?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, we use "truncation" for rounding toward zero (in contrast with ceil for +infinity and floor for -infinity) but it bears repeating.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not seen truncation defined before as anything other than "round towards zero", but adding a few extra words does no harm, so updated here.

@thisisnic thisisnic force-pushed the maths_special_cases branch 2 times, most recently from 73dc099 to c0624ec Compare September 15, 2022 13:55
Copy link
Contributor

@jvanstraten jvanstraten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now, thanks!

@jvanstraten jvanstraten merged commit 1c170c8 into substrait-io:main Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants