-
Notifications
You must be signed in to change notification settings - Fork 328
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
Reproduce Float-passing problem #9201
Conversation
|
||
vs.map v-> | ||
r = float_id v | ||
IO.println "float_id "+v.to_text+" "+r.to_text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JaroslavTulach I am seeing some unusual behavior here. I wonder if you get the same results when running Decimal_Spec.enso
locally?
This test simply passes a Float to a Java function that returns its argument. It seems like the argument is changed when it reaches the Java in some cases.
float_id 9.223372036854776E19 9.223372036854776E19
float_id 9.223372036854778E18 9.223372036854778E18
float_id 9.223372036854776E18 9.223372036854776E18
float_id 9.223372036854776E18 9.223372036854776E18
float_id 9.223372036854776E18 9.223372036854776E18
float_id 9.223372036854775E18 NaN # unexpected
float_id 9.223372036854774E18 NaN # unexpected
float_id 9.2233720368547E18 NaN # unexpected
float_id 9.223372036854E18 NaN # unexpected
float_id 9.223372E18 NaN # unexpected
float_id 9.2233720368547E17 5.148800401705924E-247 # unexpected
float_id 9.2233720368547E16 1.7265376942307606E-302 # unexpected
float_id 9.2233720368547E15 4.663754807431019E-308 # unexpected
float_id 9.2233720368547E14 9.2233720368547E14
float_id 9.2233720368547E13 9.2233720368547E13
float_id 9.223372036854E12 9.223372036854E12
float_id 9.22337203685E11 9.22337203685E11
float_id 9.2233720368E10 9.2233720368E10
float_id 9.223372036E9 9.223372036E9
float_id 9.22337203E8 9.22337203E8
float_id 9.223372E7 9.223372E7
float_id 9223372.0 9223372.0
float_id 922337.0 922337.0
float_id 92233.0 92233.0
float_id 9223.0 9223.0
float_id 922.0 922.0
float_id -9.223372036854776E19 -9.223372036854776E19
float_id -9.223372036854778E18 -9.223372036854778E18
float_id -9.223372036854776E18 -0.0 # unexpected
float_id -9.223372036854776E18 -0.0 # unexpected
float_id -9.223372036854776E18 -0.0 # unexpected
float_id -9.223372036854775E18 -5.06E-321 # unexpected
float_id -9.223372036854774E18 -1.012E-320 # unexpected
float_id -9.2233720368547E18 -3.74383E-319 # unexpected
float_id -9.223372036854E18 -3.8349E-318 # unexpected
float_id -9.223372E18 -1.8208678612E-313 # unexpected
float_id -9.2233720368547E17 -8.390303882377555E246 # unexpected
float_id -9.2233720368547E16 -2.6059089326772877E302 # unexpected
float_id -9.2233720368547E15 -8.772742498128177E307 # unexpected
float_id -9.2233720368547E14 -9.2233720368547E14
float_id -9.2233720368547E13 -9.2233720368547E13
float_id -9.223372036854E12 -9.223372036854E12
float_id -9.22337203685E11 -9.22337203685E11
float_id -9.2233720368E10 -9.2233720368E10
float_id -9.223372036E9 -9.223372036E9
float_id -9.22337203E8 -9.22337203E8
float_id -9.223372E7 -9.223372E7
float_id -9223372.0 -9223372.0
float_id -922337.0 -922337.0
float_id -92233.0 -92233.0
float_id -9223.0 -9223.0
float_id -922.0 -922.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if you get the same results when running
Decimal_Spec.enso
locally?
Yes, I do. I am seeing the same results.
This change seems to fix the problem: enso$ git diff engine/polyglot-api/src/main/java/org/enso/polyglot/HostAccessFactory.java
diff --git engine/polyglot-api/src/main/java/org/enso/polyglot/HostAccessFactory.java engine/polyglot-api/src/main/java/org/enso/polyglot/HostAccessFactory.java
index 1f9cbbcf2c..150c43fc2f 100644
--- engine/polyglot-api/src/main/java/org/enso/polyglot/HostAccessFactory.java
+++ engine/polyglot-api/src/main/java/org/enso/polyglot/HostAccessFactory.java
@@ -21,11 +21,6 @@ public class HostAccessFactory {
.allowIteratorAccess(true)
.allowMapAccess(true)
.allowAccessInheritance(true)
- .targetTypeMapping(
- Long.class,
- Double.class,
- (v) -> v != null && !longInSafeDoubleRange(v, LONG_MAX_SAFE_DOUBLE),
- (v) -> Double.longBitsToDouble(v))
.build();
}
This conversion has been added in by @hubertp. Hubert, looks like @GregoryTravis found edge cases when the conversion isn't working properly. |
We seem to have a failure related to Numeric values: can be passed in host calls without lossy coercion exception as that now ends:
I assume this is the test added by #4099 - its implementation was achieved by those five deleted lines. Now we have two options:
Removing the test can probably be done by anyone (with the blessing by someone from libraries team). Finding better lines is trickier. @hubertp please take a look and propose an alternative that wouldn't have drawbacks demonstrated in this PR and still satisfy the test. |
Removing a test is a bad practice in general, but it may be the right solution in this case. I believe the test has been written before support for has been put in place. Before the If that's the case the test may be deleted or modified to benefit from the new big integer capabilities. |
I agree that once we have proper But I don't think that was the only motivation behind #4099.
The problem is - in Enso we usually accept |
@hubertp What are your thoughts? |
Sorry, I replied to @JaroslavTulach in DM. I'm fine with ditching the test. The patch has been added prior to BigInteger support. I would also be fine in this case to make conversions explicit, rather than implicit, now. |
Should this PR be merged on its own, or does it need other changes with it? |
Once the CI is green and code owners are fine with the PR, it can be merged. |
package org.enso.base.numeric; | ||
|
||
public class Number_Utils { | ||
// For testing only. | ||
public static Double floatId(Double d) { | ||
return d; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is only used for tests, it should be moved to test/Base_Tests/polyglot-sources
. This is a Java lib specifically compiled for Base_Tests
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but I'd like to move the helper to the dedicated test library instead.
btw. @JaroslavTulach curious note for you - as you can see, we have a separate JAR built for Base_Tests
that includes some utils which are used for the tests but are not meant to be 'shipped' for users of Base
library. Do you think we can retain this structure if we merge the tests to be parts of their libraries? (I guess it would not be a big issue if we cannot, just wondering)
This applies @JaroslavTulach's fix in the comment below.
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.
./run ide build
.