Domanda

I needed to calculate exponents using GWT 2.3 in Java. ie: x^y. There's no native power operator in Java, normally you have to import java.lang.Math to use the pow() method. But you cannot do that in GWT client side (I think?).

I did temporarily solve the problem by creating my own pow() method. But I'd guess what I wrote is probably inefficient and not as good as a native solution.

private long pow(int b, int e) {
    long result = 1;
    for (int i = 0; i < e; i++) {
        result *= b;
    }
    return result;
}

So I googled for a better solution than mine and found a few people using third party libraries such as com.googlecode.gwt.math.Math. But I also found others saying these libraries only worked for GWT 2.0 or earlier because from 2.1 it was integrated within GWT. But I couldn't find any help on how to use these integrated math libraries in 2.3.

What exactly do I need to import? And how exactly do I use these libraries? Where exactly can I find official GWT documentation on these? Are they really integrated? Or should I just keep using my own method above?

È stato utile?

Soluzione

GWT can translate java.lang.Math.pow(). See this page for what parts of the Java runtime library can be emulated in Javascript by GWT.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top