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

[Java] Floating point vectors should do an approximate comparison in integration tests #16031

Closed
asfimport opened this issue Dec 2, 2016 · 7 comments
Assignees
Labels
Milestone

Comments

@asfimport
Copy link

Floating point precision rears its ugly head:

Incompatible files
Different values in column:
Field{name=float64_nullable, type=FloatingPoint{2}, children=[], layout=TypeLayout{[{width=1,type=VALIDITY}, {width=64,type=DATA}]}} at index 1: 912.4140000000002 != 912.414
10:23:45.863 [main] ERROR org.apache.arrow.tools.Integration - Incompatible files
java.lang.IllegalArgumentException: Different values in column:
Field{name=float64_nullable, type=FloatingPoint{2}, children=[], layout=TypeLayout{[{width=1,type=VALIDITY}, {width=64,type=DATA}]}} at index 1: 912.4140000000002 != 912.414

Reporter: Wes McKinney / @wesm
Assignee: Julien Le Dem / @julienledem

PRs and other links:

Note: This issue was originally created as ARROW-401. Please see the migration documentation for further details.

@asfimport
Copy link
Author

Julien Le Dem / @julienledem:
PR: #223

@asfimport
Copy link
Author

Jacques Nadeau / @jacques-n:
This is what I've used elsewhere before:

    boolean evaluateEquality(Float f1, Float f2) {
      if(f1.isNaN()){
        return f2.isNaN();
      }

      if(f1.isInfinite()){
        return f2.isInfinite();
      }

      if ((f1 + f2) / 2 != 0) {
        return Math.abs(f1 - f2) / ((f1 + f2) / 2) < 1.0E-6;
      } else {
        return !(f1 != 0);
      }
    }
    boolean evaluateEquality(Double f1, Double f2) {
      if(f1.isNaN()){
        return f2.isNaN();
      }

      if(f1.isInfinite()){
        return f2.isInfinite();
      }

      if ((f1 + f2) / 2 != 0) {
        return Math.abs(f1 - f2) / ((f1 + f2) / 2) < 1.0E-12;
      } else {
        return !(f1 != 0);
      }
    }
  }

@asfimport
Copy link
Author

Julien Le Dem / @julienledem:
what is the source for those?
Any details on why (f1 = 0) as opposed to f1 == 0 for example?

@asfimport
Copy link
Author

Jacques Nadeau / @jacques-n:
I wrote it based initially on the code here: https://github.com/mapr/drill-test-framework/blob/master/framework/src/main/java/org/apache/drill/test/framework/ColumnList.java#L115

Don't remember offhand the f1 != 0. What are the rules about NaN and Infinite in the case of a floating point negation?

@asfimport
Copy link
Author

Julien Le Dem / @julienledem:
this method will return early if f1 is NAN or infinite so there's no special case here.

@asfimport
Copy link
Author

Jacques Nadeau / @jacques-n:
good point :D

@asfimport
Copy link
Author

Julien Le Dem / @julienledem:
Issue resolved by pull request 223
#223

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants