drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paul-rogers <...@git.apache.org>
Subject [GitHub] drill pull request #863: DRILL-4970: Prevent changing the negative value of ...
Date Fri, 30 Jun 2017 02:37:16 GMT
Github user paul-rogers commented on a diff in the pull request:

    https://github.com/apache/drill/pull/863#discussion_r124953472
  
    --- Diff: exec/java-exec/src/main/codegen/templates/CastFunctions.java ---
    @@ -54,14 +56,14 @@ public void setup() {}
       public void eval() {
         <#if (type.from.startsWith("Float") && type.to.endsWith("Int"))>
         boolean sign = (in.value < 0);
    -    in.value = java.lang.Math.abs(in.value);
    -    ${type.native} fractional = in.value % 1;
    +    ${type.native} value = java.lang.Math.abs(in.value);
    +    ${type.native} fractional = value % 1;
    --- End diff --
    
    `out.value = Math.round(in.value)` ?
    
    `Math.round()` rounds a double to the closest long; handling overly large and small values,
which our code does not do. The Java method is likely to be much more efficient than this
code.
    
    Since the particular case is cast from `double` to `int`:
    
    `out.value = Math.round((float) in.value)`
    
    Returns an int.
    
    I realize that this is existing code. But, it is broken. So, we might as well fix it the
right way...


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message