Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9169d680f228
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9b1ae224f4ae
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Mar 10, 2016

  1. Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    8217ca1 View commit details
  2. [Truffle] Optimize Float#**.

    eregon committed Mar 10, 2016
    Copy the full SHA
    9b1ae22 View commit details
Showing with 23 additions and 9 deletions.
  1. +23 −9 truffle/src/main/java/org/jruby/truffle/core/numeric/FloatNodes.java
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
@@ -146,7 +147,21 @@ public PowNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
@Specialization(guards = {
"exponent == cachedExponent",
"cachedExponent >= 0",
"cachedExponent < 10" }, limit = "10")
@ExplodeLoop
public double powCached(double base, long exponent,
@Cached("exponent") long cachedExponent) {
double result = 1.0;
for (int i = 0; i < cachedExponent; i++) {
result *= base;
}
return result;
}

@Specialization(contains = "powCached")
public double pow(double a, long b) {
return Math.pow(a, b);
}
@@ -745,22 +760,21 @@ public DynamicObject toS(double value) {
str += ".0";
}

final int dot = str.indexOf('.');
assert dot != -1;

final int e = str.indexOf('e');
final boolean hasE = e != -1;

// Remove trailing zeroes
// Remove trailing zeroes, but keep at least one after the dot
final int start = hasE ? e : str.length();
int i = start;
while (i > 0 && str.charAt(i - 1) == '0') {
int i = start - 1; // last digit we keep, inclusive
while (i > dot + 1 && str.charAt(i) == '0') {
i--;
}

// But keep at least one after the dot
if (i > 0 && str.charAt(i - 1) == '.') {
i++;
}
final String formatted = str.substring(0, i + 1) + str.substring(start, str.length());

final String formatted = str.substring(0, i) + str.substring(start, str.length());
return create7BitString(formatted, USASCIIEncoding.INSTANCE);
}