Java 类java.lang.Math 实例源码

项目:smile_1.5.0_java7    文件:BinarySparseGaussianKernel.java   
@Override
public double k(int[] x, int[] y) {
    double d = 0.0;

    int p1 = 0, p2 = 0;
    while (p1 < x.length && p2 < y.length) {
        int i1 = x[p1];
        int i2 = y[p2];
        if (i1 == i2) {
            p1++;
            p2++;
        } else if (i1 > i2) {
            d++;
            p2++;
        } else {
            d++;
            p1++;
        }
    }

    d += x.length - p1;
    d += y.length - p2;

    return Math.exp(-gamma * d);
}
项目:smile_1.5.0_java7    文件:BinarySparsePolynomialKernel.java   
@Override
public double k(int[] x, int[] y) {
    double dot = 0.0;

    for (int p1 = 0, p2 = 0; p1 < x.length && p2 < y.length; ) {
        int i1 = x[p1];
        int i2 = y[p2];
        if (i1 == i2) {
            dot++;
            p1++;
            p2++;
        } else if (i1 > i2) {
            p2++;
        } else {
            p1++;
        }
    }

    return Math.pow(scale * dot + offset, degree);
}
项目:smile_1.5.0_java7    文件:BinarySparseHyperbolicTangentKernel.java   
@Override
public double k(int[] x, int[] y) {
    double dot = 0.0;

    for (int p1 = 0, p2 = 0; p1 < x.length && p2 < y.length; ) {
        int i1 = x[p1];
        int i2 = y[p2];
        if (i1 == i2) {
            dot++;
            p1++;
            p2++;
        } else if (i1 > i2) {
            p2++;
        } else {
            p1++;
        }
    }

    return Math.tanh(scale * dot + offset);
}
项目:Optics-Simulator    文件:SpecialFunction.java   
/**
 * Erf double.
 *
 * @param x the x
 * @return The Error function  Converted to Java from<BR> Cephes Math Library Release 2.2:  July,
 * 1992<BR> Copyright 1984, 1987, 1989, 1992 by Stephen L. Moshier<BR> Direct inquiries to 30 Frost Street,
 * Cambridge, MA 02140<BR>
 * @throws ArithmeticException the arithmetic exception
 */
static public double erf(double x)
        throws ArithmeticException {
    double y, z;
    double T[] = {
            9.60497373987051638749E0,
            9.00260197203842689217E1,
            2.23200534594684319226E3,
            7.00332514112805075473E3,
            5.55923013010394962768E4
    };
    double U[] = {
            //1.00000000000000000000E0,
            3.35617141647503099647E1,
            5.21357949780152679795E2,
            4.59432382970980127987E3,
            2.26290000613890934246E4,
            4.92673942608635921086E4
    };

    if( Math.abs(x) > 1.0 ) return( 1.0 - erfc(x) );
    z = x * x;
    y = x * polevl( z, T, 4 ) / p1evl( z, U, 5 );
    return y;
}
项目:openjdk-jdk10    文件:TestInterpreterMethodEntries.java   
public static void main(String[] args) throws Exception {
    if (args.length == 0) {
      // Dump and use shared archive with different flag combinations
      dumpAndUseSharedArchive("+", "-");
      dumpAndUseSharedArchive("-", "+");
    } else {
      // Call intrinsified java.lang.Math::fma()
      Math.fma(1.0, 2.0, 3.0);

      byte[] buffer = new byte[256];
      // Call intrinsified java.util.zip.CRC32::update()
      CRC32 crc32 = new CRC32();
      crc32.update(buffer, 0, 256);

      // Call intrinsified java.util.zip.CRC32C::updateBytes(..)
      CRC32C crc32c = new CRC32C();
      crc32c.update(buffer, 0, 256);
    }
}
项目:react-native-camera    文件:RCTCamera.java   
private Camera.Size getClosestSize(List<Camera.Size> supportedSizes, int matchWidth, int matchHeight) {
  Camera.Size closestSize = null;
  for (Camera.Size size : supportedSizes) {
      if (closestSize == null) {
          closestSize = size;
          continue;
      }

      int currentDelta = Math.abs(closestSize.width - matchWidth) * Math.abs(closestSize.height - matchHeight);
      int newDelta = Math.abs(size.width - matchWidth) * Math.abs(size.height - matchHeight);

      if (newDelta < currentDelta) {
          closestSize = size;
      }
  }
  return closestSize;
}
项目:monarch    文件:ListenerIdMap.java   
/**
 * Removes the mapping for the given key. Returns the object to which the key was mapped, or
 * <code>null</code> otherwise.
 */
public Object remove(int key) {
  Entry[] table = this.table;
  int bucket = Math.abs(key) % table.length;

  for (Entry e = table[bucket], prev = null; e != null; prev = e, e = e.next) {
    if (key == e.key) {
      if (prev != null)
        prev.next = e.next;
      else
        table[bucket] = e.next;

      count--;
      Object oldValue = e.value;
      e.value = null;
      return oldValue;
    }
  }

  return null;
}
项目:TextHIN    文件:SimilarityMeasures.java   
public static double computeCosineSimilarity(IntArrayList indexA, DoubleArrayList valueA, DoubleMatrix1D B, DoubleArrayList valueB)
{
    double sim = -1;

    double num = 0;
    double den = 0;
    double den_1 = 0;
    double den_2 = 0;

    num = Matrix2DUtil.productQuick(indexA, valueA, B);
    den_1 = Matrix2DUtil.getSqrSum(valueA);
    den_2 = Matrix2DUtil.getSqrSum(valueB);
    den = Math.sqrt(den_1) * Math.sqrt(den_2);
    if(den == 0)
        return 0;
    sim = num/den;
    return sim;
}
项目:TextHIN    文件:SimilarityMeasures.java   
public static double computeCosineSimilarity(DoubleMatrix1D a, DoubleMatrix1D b)
{
    double sim = -1;
    if (a.size() != b.size())
    {
        System.err.println("mismatched size");
        return -1;
    }

    double num = 0;
    double den = 0;
    double den_1 = 0;
    double den_2 = 0;

    num = Matrix2DUtil.productQuick(a, b);
    den_1 = Matrix2DUtil.getSqrSum(a);
    den_2 = Matrix2DUtil.getSqrSum(b);
    den = Math.sqrt(den_1) * Math.sqrt(den_2);
    if(den == 0)
        return 0;
    sim = num/den;
    return sim;
}
项目:TextHIN    文件:SimilarityMeasures.java   
public static double computeCosineSimilarity(double[] a, double[] b)
{
    double sim = -1;
    if(a.length != b.length)
        return sim;
    double num = 0;
    double den = 0;
    double den_1 = 0;
    double den_2 = 0;
    for(int i = 0; i < a.length; i++)
    {
        num += a[i] * b[i];
        den_1 += a[i]*a[i];
        den_2 += b[i]*b[i];
    }
    den = Math.sqrt(den_1) * Math.sqrt(den_2);
    if(den == 0)
        return 0;
    sim = num/den;
    return sim;
}
项目:PiPle    文件:Window.java   
/**
 * checks if pt is on root and calls itself recursivly to check root's children
 * @param pt the point we want to check the location of
 * @param root the message we want to check if the point is on
 * @return root if pt is on it, null otherwise
 * @author Paul Best
 */
public Message clickedOn(Point pt, Message root){
    Message answer;
    for(int i = 0; i<root.getChildren().size();i++){
        answer = clickedOn(pt,root.getChildren().get(i));
        if(answer!=null){
            return  answer;
        }
    }
    if(Math.pow(Math.pow(pt.x/mScaleFactor-(root.getGoval().getX()+mPosX/mScaleFactor),2)+Math.pow(pt.y/mScaleFactor-(root.getGoval().getY()+mPosY/mScaleFactor),2),0.5)<root.getGoval().getRay()){
        return root;
    }
    else{
        return null;
    }
}
项目:Java-Lab-Programs    文件:Quad.java   
public static void main(String args[]) throws IOException{
    BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
    double a,b,c,d,x1,x2;
    System.out.print("Input value of a-->");
    a = Double.parseDouble(obj.readLine());
    System.out.print("Input value of b-->");
    b = Double.parseDouble(obj.readLine());
    System.out.print("Input value of c-->");
    c = Double.parseDouble(obj.readLine());
    d = (b*b) - (4*a*c);
    if( d < 0)
    {
        System.out.println("There are no real solution");
        System.exit(0);
    }

    x1 = (-b + Math.sqrt(d))/(2*a);
    x2 = (-b - Math.sqrt(d))/(2*a);
    System.out.println("Roots of equation are " + x1 + " and " + x2);
}
项目:monarch    文件:ObjIdMap.java   
/**
 * Removes the mapping for the given key. Returns the object to which the key was mapped, or
 * <code>null</code> otherwise.
 */
public Object remove(int key) {
  Entry[] table = this.table;
  int bucket = Math.abs(key) % table.length;

  for (Entry e = table[bucket], prev = null; e != null; prev = e, e = e.next) {
    if (key == e.key) {
      if (prev != null)
        prev.next = e.next;
      else
        table[bucket] = e.next;

      count--;
      Object oldValue = e.value;
      e.value = null;
      return oldValue;
    }
  }

  return null;
}
项目:MonkeyCrypt    文件:Hill.java   
/**
 * @param text (Klartext), key (Schluessel)
 *
 * @return algorithm() (Geheimtext)
 */

public String encrypt(String text, String key)
{
    currentAlphabet = myAlphabet.getAlphabet();
    String verified = verify(key, currentAlphabet);
    key = key.toLowerCase();
    String shortText = Tools.onlyAlphabet(text, currentAlphabet);
    if (verified != null){
        return verified;
    }
    int dimension = (int) Math.sqrt(key.length());
    while (shortText.length()%(dimension) != 0){
        shortText += currentAlphabet.charAt(0);
    }

    int [][] keyMatrix = Tools.makeMatrix(key, dimension, dimension, currentAlphabet);          
    String newText = algorithm(shortText, keyMatrix, currentAlphabet, dimension);
    return newText;


}
项目:MonkeyCrypt    文件:Hill.java   
@Override
protected String verify(String key, String alphabet) {
    if (!checkLength(key, length)){
        return "Vorsicht! Fülle die Schlüsselmatrix vollständig mit je einem Zeichen aus!";
    }
    else if(!checkCharacter(key, alphabet)){
        return "Vorsicht! Die Schlüsselmatrix darf nur Zeichen enthalten, die auch im Alphabet enthalten sind!";
    }
    else{
        int dimension = (int) Math.sqrt(key.length());
        int [][] keyMatrix = Tools.makeMatrix(key, dimension, dimension, currentAlphabet);
        if (!checkDeterminant(keyMatrix)){
            return "Vorsicht! Die Determinante der Schlüsselmatrix ist 0. Dein Text kann daher nicht eindeutig entschlüsselt werden!";
        }
        else{
            int determinant = Tools.modInverse(MatrixTools.determinant(keyMatrix), currentAlphabet);
            if (determinant == 0) {
                return "Vorsicht! Die Schlüsselmatrix hat keine Inverse. Dein Text kann daher nicht eindeutig verschlüsselt werden!";
            }
            return null;
        }
    }
}
项目:GOLAD    文件:MyWorld.java   
public String getCaryString(){
    int humanNum = 0;
    int timeLimitNum=99999;
    int timeBonusNum=99999;
    if(redBot){
        humanNum+=(2*redDepth+4);//(redDepth/2+1)*4
    }
    if(blueBot){
        humanNum+=(blueDepth/2+1);
    }
    if(timeLimit[1]!=Integer.MAX_VALUE){
        timeLimitNum = timeLimit[1];
        timeBonusNum = timeBonus;
    }
    if(screen==2){
        boardStart = getBoard();
        moveSequence = "";
    }
    String result = rules+","+Math.max(WIDTH,HEIGHT)+","+timeLimitNum+","+timeBonusNum+","+humanNum+","+boardStart+moveSequence;
    return result;
}
项目:reto    文件:Jug.java   
/**
 * Empty partially or totally the actual amount, depends on the other jug, 
 * filling that quantity in the other jug
 * @param jug Other jug where to dump into.
 */
public void dumpInto(Jug jug) {
    /**
     * The quantity to fill. It will be the rest of the other jug or the 
     * actual amount, if it is smaller.
     */
    Integer added = Math.min(jug.rest(), getAmount());

    // set the amount of the other jug to indicate the filling
    jug.setAmount(jug.getAmount() + added);

    // set the actual amount of this jug to indicate the dump
    setAmount(amount - added);
}
项目:CS445_Spring2017    文件:BSTCopyDemo.java   
/**
    * Return height of this tree
    * Note this is recursive!
    * Base case - no child nodes
    * Recursive cases - L or R child node, or both
    * @return int height of tree
    */

   public int height() {

// Fill in placeholder "impossible" value of -1

int leftHeight = -1;
int rightHeight = -1;

// If left is null, then height from left on down is 1
// We auto-add one as part of the return statement so set
// to 0.
// Otherwise, recurse to find height

if (left == null) {
    leftHeight = 0;
} else {
    leftHeight = left.height();
}

// If right is null, then height from right on down is 1
// We auto-add one as part of the return statement so set
// to 0.
// Otherwise, recurse to find height

if (right == null) {
    rightHeight = 0;
} else {
    rightHeight = right.height();
}

// Return the greater of left or right height
return 1 + Math.max(leftHeight, rightHeight);
   }
项目:smile_1.5.0_java7    文件:HellingerKernel.java   
@Override
public double k(double[] x, double[] y) {
    if (x.length != y.length)
        throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length));

    double sum = 0;
    for (int i = 0; i < x.length; i++) {
        sum += Math.sqrt(x[i] * y[i]);
    }

    return sum;
}
项目:bombsquad-remote-android    文件:GamePadActivity.java   
void _doStateChangeV1(boolean force) {

        //Log.v(TAG,"S "+_dPadStateH+" "+_dPadStateV);

        // compile our state value
        short s = _buttonStateV1; // buttons
        s |= (_dPadStateH > 0 ? 1 : 0) << 5; // sign bit
        s |= ((int) (Math.round(Math.min(1.0, Math.abs(_dPadStateH)) * 15.0))) << 6; // mag
        s |= (_dPadStateV > 0 ? 1 : 0) << 10; // sign bit
        s |= ((int) (Math.round(Math.min(1.0, Math.abs(_dPadStateV)) * 15.0))) << 11; // mag

        // if our compiled state value hasn't changed, don't send.
        // (analog joystick noise can send a bunch of redundant states through
        // here)
        // The exception is if forced is true, which is the case with packets
        // that
        // double as keepalives.
        if ((s == _lastSentState) && (!force))
            return;

        _stateBirthTimes[_nextState] = SystemClock.uptimeMillis();
        _stateLastSentTimes[_nextState] = 0;

        if (debug) Log.v(TAG, "STORING NEXT STATE: " + _nextState);
        _statesV1[_nextState] = s;
        _nextState = (_nextState + 1) % 256;
        _lastSentState = s;

        // if we're pretty up to date as far as state acks, lets go ahead
        // and send out this state immediately..
        // (keeps us nice and responsive on low latency networks)
        int unackedCount = (_nextState - _requestedState) & 0xFF; // upcast to
                                                                    // get
                                                                    // unsigned
        if (unackedCount < 0) throw new AssertionError();
        if (unackedCount < 3) {
            _shipUnAckedStatesV1();
        }
    }
项目:smile_1.5.0_java7    文件:BinarySparseLaplacianKernel.java   
@Override
public double k(int[] x, int[] y) {
    if (x.length != y.length)
        throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length));

    double d = 0.0;
    int p1 = 0, p2 = 0;
    while (p1 < x.length && p2 < y.length) {
        int i1 = x[p1];
        int i2 = y[p2];
        if (i1 == i2) {
            p1++;
            p2++;
        } else if (i1 > i2) {
            d++;
            p2++;
        } else {
            d++;
            p1++;
        }
    }

    d += x.length - p1;
    d += y.length - p2;

    return Math.exp(-gamma * Math.sqrt(d));
}
项目:parabuild-ci    文件:SetFunction.java   
private Number getStdDev() {

        if (!initialized) {
            return null;
        }

        return sample ? (n == 1) ? null    // NULL (not NaN) is correct in this case
                                 : new Double(Math.sqrt(vk / (double) (n - 1)))
                      : new Double(Math.sqrt(vk / (double) (n)));
    }
项目:monarch    文件:ListenerIdMap.java   
/**
 * Returns the object to which the given key is mapped. If no object is mapped to the given key,
 * <code>null</code> is returned.
 *
 * @throws IllegalArgumentException <code>key</code> is less than zero
 */
public Object get(int key) {

  Entry[] table = this.table;
  int bucket = Math.abs(key) % table.length;
  for (Entry e = table[bucket]; e != null; e = e.next) {
    if (e.key == key) {
      return e.value;
    }
  }

  return null;
}
项目:Optics-Simulator    文件:SpecialFunction.java   
/**
 * Cosh double.
 *
 * @param x a double value
 * @return the hyperbolic cosine of the argument
 * @throws ArithmeticException the arithmetic exception
 */
static public double cosh(double x) throws ArithmeticException {
    double a;
    a = x;
    if( a < 0.0 ) a = Math.abs(x);
    a = Math.exp(a);
    return 0.5*(a+1/a);
}
项目:Notes    文件:Norm.java   
public double norm(double[] v) {
    int nLen = v.length;
    double sum = 0;
    for (int i = 0; i < nLen; i++) {
        sum += Math.pow(v[i], 2.0);
    }
    return Math.sqrt(sum);
}
项目:Optics-Simulator    文件:SpecialFunction.java   
/**
 * Tanh double.
 *
 * @param x a double value
 * @return the hyperbolic tangent of the argument
 * @throws ArithmeticException the arithmetic exception
 */
static public double tanh(double x) throws ArithmeticException {
    double a;
    if( x == 0.0 ) return x;
    a = x;
    if( a < 0.0 ) a = Math.abs(x);
    a = Math.exp(2.0*a);
    if(x < 0.0 ) return -( 1.0-2.0/(a+1.0) );
    else         return  ( 1.0-2.0/(a+1.0) );
}
项目:AACS2204    文件:T2Q3.java   
public static void main(String[] args) {
    double x=10,y=20,z=30;
    System.out.println(Math.sqrt(Math.pow(x,(1/y))));
    for(int i=0;i<100;i++) System.out.println((int)(Math.random() * 100));
    NetPayer np = new NetPayer();
    NetPayer np2 = new NetPayer();
    System.out.println("RM " + np.computeNetPay(8) + " paid");
    System.out.println("RM " + np.k + " paid");
    np.k = 1000;
    System.out.println("RM " + np2.k + " paid");

}
项目:Optics-Simulator    文件:SpecialFunction.java   
/**
 * Asinh double.
 *
 * @param xx the xx
 * @return the hyperbolic arc sine of the argument
 * @throws ArithmeticException the arithmetic exception
 */
static public double asinh(double xx) throws ArithmeticException {
    double x;
    int sign;
    if(xx == 0.0) return xx;
    if( xx < 0.0 ) {
        sign = -1;
        x = -xx;
    } else {
        sign = 1;
        x = xx;
    }
    return sign*Math.log( x + Math.sqrt(x*x+1));
}
项目:Optics-Simulator    文件:SpecialFunction.java   
/**
 * J 1 double.
 *
 * @param x a double value
 * @return the Bessel function of order 1 of the argument.
 * @throws ArithmeticException the arithmetic exception
 */

static public double j1(double x) throws ArithmeticException {

    double ax;
    double y;
    double ans1, ans2;

    if ((ax=Math.abs(x)) < 8.0) {
        y=x*x;
        ans1=x*(72362614232.0+y*(-7895059235.0+y*(242396853.1
                +y*(-2972611.439+y*(15704.48260+y*(-30.16036606))))));
        ans2=144725228442.0+y*(2300535178.0+y*(18583304.74
                +y*(99447.43394+y*(376.9991397+y*1.0))));
        return ans1/ans2;
    } else {
        double z=8.0/ax;
        double xx=ax-2.356194491;
        y=z*z;

        ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4
                +y*(0.2457520174e-5+y*(-0.240337019e-6))));
        ans2=0.04687499995+y*(-0.2002690873e-3
                +y*(0.8449199096e-5+y*(-0.88228987e-6
                +y*0.105787412e-6)));
        double ans=Math.sqrt(0.636619772/ax)*
                (Math.cos(xx)*ans1-z*Math.sin(xx)*ans2);
        if (x < 0.0) ans = -ans;
        return ans;
    }
}
项目:CS445_Spring2017    文件:BSTTraverseDemo.java   
/**
    * Return height of this tree
    * Note this is recursive!
    * Base case - no child nodes
    * Recursive cases - L or R child node, or both
    * @return int height of tree
    */

   public int height() {

// Fill in placeholder "impossible" value of -1

int leftHeight = -1;
int rightHeight = -1;

// If left is null, then height from left on down is 1
// We auto-add one as part of the return statement so set
// to 0.
// Otherwise, recurse to find height

if (left == null) {
    leftHeight = 0;
} else {
    leftHeight = left.height();
}

// If right is null, then height from right on down is 1
// We auto-add one as part of the return statement so set
// to 0.
// Otherwise, recurse to find height

if (right == null) {
    rightHeight = 0;
} else {
    rightHeight = right.height();
}

// Return the greater of left or right height
return 1 + Math.max(leftHeight, rightHeight);
   }
项目:GravityBox    文件:KeyButtonView.java   
public void setQuiescentAlpha(float alpha, boolean animate) {
    mAnimateToQuiescent.cancel();
    alpha = Math.min(Math.max(alpha, 0), 1);
    if (alpha == mQuiescentAlpha && alpha == mDrawingAlpha) return;
    mQuiescentAlpha = alpha;
    if (DEBUG) Log.d(TAG, "New quiescent alpha = " + mQuiescentAlpha);
    if (animate) {
        mAnimateToQuiescent = animateToQuiescent();
        mAnimateToQuiescent.start();
    } else {
        setDrawingAlpha(mQuiescentAlpha);
    }
}
项目:Optics-Simulator    文件:SpecialFunction.java   
/**
 * Igam double.
 *
 * @param a double value
 * @param x double value
 * @return the Incomplete Gamma function.  Converted to Java from<BR> Cephes Math Library Release
 * 2.2:  July, 1992<BR> Copyright 1984, 1987, 1989, 1992 by Stephen L. Moshier<BR> Direct inquiries to 30 Frost
 * Street, Cambridge, MA 02140<BR>
 * @throws ArithmeticException the arithmetic exception
 */
static public double igam(double a, double x)
        throws ArithmeticException {


    double ans, ax, c, r;

    if( x <= 0 || a <= 0 ) return 0.0;

    if( x > 1.0 && x > a ) return 1.0 - igamc(a,x);

   /* Compute  x**a * exp(-x) / gamma(a)  */
    ax = a * Math.log(x) - x - lgamma(a);
    if( ax < -MAXLOG ) return( 0.0 );

    ax = Math.exp(ax);

    /* power series */
    r = a;
    c = 1.0;
    ans = 1.0;

    do {
        r += 1.0;
        c *= x/r;
        ans += c;
    }
    while( c/ans > MACHEP );

    return( ans * ax/a );

}
项目:parabuild-ci    文件:SetFunction.java   
private Number getStdDev() {

        if (!initialized) {
            return null;
        }

        return sample ? (n == 1) ? null    // NULL (not NaN) is correct in this case
                                 : new Double(Math.sqrt(vk
                                 / (double) (n - 1)))
                      : new Double(Math.sqrt(vk / (double) (n)));
    }
项目:Optics-Simulator    文件:SpecialFunction.java   
/**
 * Pseries double.
 *
 * @param a the a
 * @param b the b
 * @param x the x
 * @return the double
 * @throws ArithmeticException the arithmetic exception
 */
static private  double pseries( double a, double b, double x )
        throws ArithmeticException {
    double s, t, u, v, n, t1, z, ai;

    ai = 1.0 / a;
    u = (1.0 - b) * x;
    v = u / (a + 1.0);
    t1 = v;
    t = u;
    n = 2.0;
    s = 0.0;
    z = MACHEP * ai;
    while( Math.abs(v) > z ) {
        u = (n - b) * x / n;
        t *= u;
        v = t / (a + n);
        s += v;
        n += 1.0;
    }
    s += t1;
    s += ai;

    u = a * Math.log(x);
    if( (a+b) < MAXGAM && Math.abs(u) < MAXLOG ) {
        t = gamma(a+b)/(gamma(a)*gamma(b));
        s = s * t * Math.pow(x,a);
    } else {
        t = lgamma(a+b) - lgamma(a) - lgamma(b) + u + Math.log(s);
        if( t < MINLOG )    s = 0.0;
        else                s = Math.exp(t);
    }
    return s;
}
项目:chatbot    文件:Decomp.java   
/**
 *  Step to the next reassembly rule.
 *  If mem is true, pick a random rule.
 */
public void stepRule() {
    int size = reasemb.size();
    if (mem) {
        currReasmb = (int)(Math.random() * size);
    }
    //  Increment and make sure it is within range.
    currReasmb++;
    if (currReasmb >= size) currReasmb = 0;
}
项目:joai-project    文件:ChoiceGuard.java   
/**
* Returns the smallest of the minOccurs attributes of the choice members.
*/
int minMemberOccurs () {
    int minOccurs = Integer.MAX_VALUE;
    for (Iterator i=compositor.getMembers().iterator();i.hasNext();) {
        CompositorMember member = (CompositorMember)i.next();
        minOccurs = Math.min(minOccurs, member.minOccurs);
    }
    return minOccurs;
}
项目:missile-defense    文件:Missile.java   
/**
     * Default constructor. Intended for enemies.
     */
    public Missile(MainApplication app, String spriteLoc) {
        program = app;
        isFriendly = false;
        isDestroyed = false;
        this.rng = new Random();
        x = rng.nextInt(1024);
        y = 0;
        radius = 10;
        angle = 135 * this.rng.nextDouble() - 135;
        if (angle <= 15 && angle >= 0) {
            angle += 25;
        } else if (angle >= -15 && angle < 0) {
            angle -= 25;
        }
        roundedAngle = Math.abs((int)Math.round(angle/15)*15);

        String spriteLoc2 = "Missiles/EnemyMissile_R" + roundedAngle + ".png";
//      System.out.println("Theta = " + roundedAngle);
        System.out.println(spriteLoc2);

        sprite = SpriteStore.get().getSprite(spriteLoc2);

        isHit = false;

        this.hitbox = new GRectangle(x, y, Missile.WIDTH, Missile.HEIGHT); //TODO need to make the hit box reflect the orientation/size of the missile
        this.sprite.scale(SCALE, SCALE);

        //TODO remove, test only to generate the boxes for visual example
//      hitbox.setColor(Color.BLUE);
//      hitbox.setFilled(true);

        System.out.print("r: " + radius + " theta (exact): " + angle + " theta (rounded): " + roundedAngle + "\n" );

        //TODO remove, test only to generate the boxes for visual example
        if(this.DEBUG_MODE == true){
            this.debugHitbox = new GRect(x, y, Missile.WIDTH, Missile.HEIGHT); 
        }

    }
项目:SerialAssistant    文件:Raw.java   
public int read( byte b[], int off, int len ) throws IOException 
{
    dataAvailable=0;
    int i=0, Minimum=0;
    int intArray[] = 
    {
        b.length,
        InputBuffer, 
        len
    };
/*
    find the lowest nonzero value
    timeout and threshold are handled on the native side
    see  NativeEnableReceiveTimeoutThreshold in
    RawImp.c
*/
    while(intArray[i]==0 && i < intArray.length) i++;
    Minimum=intArray[i];
    while( i < intArray.length )
    {
        if(intArray[i] > 0 )
        {
            Minimum=Math.min(Minimum,intArray[i]);
        }
        i++;
    }
    Minimum=Math.min(Minimum,threshold);
    if(Minimum == 0) Minimum=1;
    int Available=available();
    int Ret = readArray( b, off, Minimum);
    return Ret;
}
项目:SerialAssistant    文件:I2C.java   
public int read( byte b[], int off, int len ) throws IOException 
{
    dataAvailable=0;
    int i=0, Minimum=0;
    int intArray[] = 
    {
        b.length,
        InputBuffer, 
        len
    };
/*
    find the lowest nonzero value
    timeout and threshold are handled on the native side
    see  NativeEnableReceiveTimeoutThreshold in
    I2CImp.c
*/
    while(intArray[i]==0 && i < intArray.length) i++;
    Minimum=intArray[i];
    while( i < intArray.length )
    {
        if(intArray[i] > 0 )
        {
            Minimum=Math.min(Minimum,intArray[i]);
        }
        i++;
    }
    Minimum=Math.min(Minimum,threshold);
    if(Minimum == 0) Minimum=1;
    int Available=available();
    int Ret = readArray( b, off, Minimum);
    return Ret;
}
项目:BNPMix.java    文件:Summary.java   
public void add(double x) {
    sum_x += x;
    sum_xx += x*x;
    num_x += 1.0;
    min_x = Math.min(min_x,x);
    max_x = Math.max(max_x,x);
}