Skip to content

Commit

Permalink
[truffle] Smart numify doubles
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Jul 5, 2018
1 parent 527fe84 commit ded1527
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Expand Up @@ -14,9 +14,8 @@ public NQPCoerceNumToStrNode(NQPNode argNode) {
this.argNode = argNode;
}

@Override
public String executeStr(VirtualFrame frame) {
double in = argNode.executeNum(frame);

public static String coerce(double in) {
if (in == (long)in) {
if (in == 0 && Double.toString(in).equals("-0.0")) {
return "-0";
Expand All @@ -33,4 +32,10 @@ public String executeStr(VirtualFrame frame) {
return Double.toString(in);
}
}

@Override
public String executeStr(VirtualFrame frame) {
double in = argNode.executeNum(frame);
return coerce(in);
}
}
Expand Up @@ -66,7 +66,10 @@ public String executeStr(VirtualFrame frame) {
return (String) value;
} else if (value instanceof Long) {
return ((Long) value).toString();
} else if (value instanceof Double) {
return NQPCoerceNumToStrNode.coerce((double) value);
} else {
throw new RuntimeException("can't smart stringify: " + value.getClass().getCanonicalName());
}
throw new RuntimeException("can't smart stringify: " + value.getClass().getCanonicalName());
}
}

0 comments on commit ded1527

Please sign in to comment.