OpenRefine icon indicating copy to clipboard operation
OpenRefine copied to clipboard

Integer divide by zero returns null instead of error or infinity

Open tfmorris opened this issue 1 year ago • 2 comments

Our divide by zero behavior is currently inconsistent and should be cleaned up

Current Results

0 / 0 == NaN
0.0 / 0.0 = NaN
1 / 0 == null
1.1 / 0 == Infinity
-1.1 / 0 == -Infinity

Expected Behavior

There are a couple of reasonable solutions (null isn't one of them):

  1. return an error
  2. return Infinity or -Infinity

I'd argue for 2, since we're already returning NaN for 0/0, effectively promoting the integer operands to a floating point result, and this would be the equivalent.

Screenshots

Screenshot 2024-02-21 at 1 14 25 PM

Additional context

As an aside, when testing this I (re)discovered that there's no way to get a floating point 1.0. It will always get demoted back to an integer which is kind of taking the whole polymorphism thing to an extreme.

tfmorris avatar Feb 21 '24 18:02 tfmorris

Happy with either approach 1 or 2 as you describe.

I'm interested in the floating point vs integer question but maybe this needs a separate discussion either via forum or a separate GitHub issue?

ostephens avatar Feb 22 '24 11:02 ostephens

@ostephens Thanks for the feedback. On reflection, I think the 1.0 behavior is a symptom of https://github.com/OpenRefine/OpenRefine/issues/5469#issuecomment-1334611706

tfmorris avatar Feb 22 '24 18:02 tfmorris

@tfmorris is it possible I work on this issue or it has already been assigned to someone else (talking about the division by zero and not the 1.0 getting demoted to an integer).

Kurocifer avatar Jul 05 '24 14:07 Kurocifer

@Kurocifer It's actually assigned to me, as you can see in the upper right of the page, but since you've created a PR, I'll review it.

tfmorris avatar Jul 07 '24 03:07 tfmorris