當前位置: 首頁>>代碼示例>>Java>>正文


Java Math類代碼示例

本文整理匯總了Java中java.lang.Math的典型用法代碼示例。如果您正苦於以下問題:Java Math類的具體用法?Java Math怎麽用?Java Math使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Math類屬於java.lang包,在下文中一共展示了Math類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: k

import java.lang.Math; //導入依賴的package包/類
@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);
}
 
開發者ID:takun2s,項目名稱:smile_1.5.0_java7,代碼行數:26,代碼來源:BinarySparseGaussianKernel.java

示例2: k

import java.lang.Math; //導入依賴的package包/類
@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);
}
 
開發者ID:takun2s,項目名稱:smile_1.5.0_java7,代碼行數:21,代碼來源:BinarySparsePolynomialKernel.java

示例3: k

import java.lang.Math; //導入依賴的package包/類
@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);
}
 
開發者ID:takun2s,項目名稱:smile_1.5.0_java7,代碼行數:21,代碼來源:BinarySparseHyperbolicTangentKernel.java

示例4: erf

import java.lang.Math; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:RudyB,項目名稱:Optics-Simulator,代碼行數:34,代碼來源:SpecialFunction.java

示例5: main

import java.lang.Math; //導入依賴的package包/類
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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:TestInterpreterMethodEntries.java

示例6: getClosestSize

import java.lang.Math; //導入依賴的package包/類
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;
}
 
開發者ID:jonathan68,項目名稱:react-native-camera,代碼行數:18,代碼來源:RCTCamera.java

示例7: remove

import java.lang.Math; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:25,代碼來源:ListenerIdMap.java

示例8: computeCosineSimilarity

import java.lang.Math; //導入依賴的package包/類
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;
}
 
開發者ID:cgraywang,項目名稱:TextHIN,代碼行數:19,代碼來源:SimilarityMeasures.java

示例9: clickedOn

import java.lang.Math; //導入依賴的package包/類
/**
 * 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;
    }
}
 
開發者ID:jkobject,項目名稱:PiPle,代碼行數:23,代碼來源:Window.java

示例10: main

import java.lang.Math; //導入依賴的package包/類
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);
}
 
開發者ID:nvzard,項目名稱:Java-Lab-Programs,代碼行數:21,代碼來源:Quad.java

示例11: encrypt

import java.lang.Math; //導入依賴的package包/類
/**
 * @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;

	
}
 
開發者ID:PSeminarKryptographie,項目名稱:MonkeyCrypt,代碼行數:27,代碼來源:Hill.java

示例12: verify

import java.lang.Math; //導入依賴的package包/類
@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;
		}
	}
}
 
開發者ID:PSeminarKryptographie,項目名稱:MonkeyCrypt,代碼行數:24,代碼來源:Hill.java

示例13: getCaryString

import java.lang.Math; //導入依賴的package包/類
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;
}
 
開發者ID:hanss314,項目名稱:GOLAD,代碼行數:22,代碼來源:MyWorld.java

示例14: dumpInto

import java.lang.Math; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:VigoTech,項目名稱:reto,代碼行數:19,代碼來源:Jug.java

示例15: height

import java.lang.Math; //導入依賴的package包/類
/**
    * 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);
   }
 
開發者ID:laboon,項目名稱:CS445_Spring2017,代碼行數:41,代碼來源:BSTCopyDemo.java


注:本文中的java.lang.Math類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。