本文整理匯總了Java中java.lang.Math.abs方法的典型用法代碼示例。如果您正苦於以下問題:Java Math.abs方法的具體用法?Java Math.abs怎麽用?Java Math.abs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.Math
的用法示例。
在下文中一共展示了Math.abs方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: normal
import java.lang.Math; //導入方法依賴的package包/類
/**
* Normal double.
*
* @param a double value
* @return The area under the Gaussian probability density function, integrated from minus infinity to x:
* @throws ArithmeticException the arithmetic exception
*/
static public double normal( double a)
throws ArithmeticException {
double x, y, z;
x = a * SQRTH;
z = Math.abs(x);
if( z < SQRTH ) y = 0.5 + 0.5 * erf(x);
else {
y = 0.5 * erfc(z);
if( x > 0 ) y = 1.0 - y;
}
return y;
}
示例3: containsKey
import java.lang.Math; //導入方法依賴的package包/類
/**
* Returns <code>true</code> if this map contains a mapping for the given key.
*
* @throws IllegalArgumentException <code>key</code> is less than zero
*/
public boolean containsKey(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 true;
}
}
return false;
}
示例4: rehash
import java.lang.Math; //導入方法依賴的package包/類
private void rehash(Entry[] oldMap, int newCount, int newCapacity) {
int oldCapacity = oldMap.length;
Entry newMap[] = new Entry[newCapacity];
synchronized (rehashLock) {
for (int i = oldCapacity; i-- > 0;) {
for (Entry old = oldMap[i]; old != null;) {
Entry e = old;
old = old.next;
if (e.value != null && e.value instanceof WeakReference) {
WeakReference r = (WeakReference) e.value;
if (r.get() == null) {
// don't copy this one into the new table since its value was gc'd
newCount--;
continue;
}
}
int index = Math.abs(e.key) % newCapacity;
e.next = newMap[index];
newMap[index] = e;
}
}
threshold = (int) (newCapacity * loadFactor);
count = newCount;
table = newMap;
}
}
示例5: Missile
import java.lang.Math; //導入方法依賴的package包/類
/**
* 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);
}
}
示例6: completeState
import java.lang.Math; //導入方法依賴的package包/類
protected void completeState()
{
double cx = 0, cy = 0;
double mu20, mu11, mu02;
double inv_m00 = 0.0;
if( Math.abs(this.m00) > 0.00000001 )
{
inv_m00 = 1. / this.m00;
cx = this.m10 * inv_m00;
cy = this.m01 * inv_m00;
}
// mu20 = m20 - m10*cx
mu20 = this.m20 - this.m10 * cx;
// mu11 = m11 - m10*cy
mu11 = this.m11 - this.m10 * cy;
// mu02 = m02 - m01*cy
mu02 = this.m02 - this.m01 * cy;
this.mu20 = mu20;
this.mu11 = mu11;
this.mu02 = mu02;
// mu30 = m30 - cx*(3*mu20 + cx*m10)
this.mu30 = this.m30 - cx * (3 * mu20 + cx * this.m10);
mu11 += mu11;
// mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20
this.mu21 = this.m21 - cx * (mu11 + cx * this.m01) - cy * mu20;
// mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02
this.mu12 = this.m12 - cy * (mu11 + cy * this.m10) - cx * mu02;
// mu03 = m03 - cy*(3*mu02 + cy*m01)
this.mu03 = this.m03 - cy * (3 * mu02 + cy * this.m01);
double inv_sqrt_m00 = Math.sqrt(Math.abs(inv_m00));
double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00;
this.nu20 = this.mu20*s2;
this.nu11 = this.mu11*s2;
this.nu02 = this.mu02*s2;
this.nu30 = this.mu30*s3;
this.nu21 = this.mu21*s3;
this.nu12 = this.mu12*s3;
this.nu03 = this.mu03*s3;
}
示例7: paintComponent
import java.lang.Math; //導入方法依賴的package包/類
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
this.setBackground(Color.WHITE);
int prevX = -1, prevY = -1;
for(int i = 0; i < dots.size(); i++){
g.setColor(dots.get(i).getColor());
if(i>0){
//Only fill gap if next Dot has an offset of more
//than half of it's thickness from previous Dot.
if(((Math.abs(dots.get(i).getX()-prevX)>(int)(Settings.THICK/2)) || (Math.abs(dots.get(i).getY()-prevY)>(int)(Settings.THICK/2))) &&
dots.get(i-1).inLine() == Dot.INLINE && dots.get(i).inLine() == Dot.INLINE ){
Graphics2D g2d = (Graphics2D) g.create();
BasicStroke stroke;
switch(Settings.STYLE){
case 0: stroke = new BasicStroke((float) Settings.THICK);
break;
case 1: stroke = new BasicStroke((float) Settings.THICK, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
break;
default: stroke = new BasicStroke((float) Settings.THICK);
break;
}
g2d.setStroke(stroke);
//+(int)(this.THICK/2) used in order for line to
// start from middle of previous Dot.
g2d.drawLine(prevX+(int)(Settings.THICK/2), prevY+(int)(Settings.THICK/2),
dots.get(i).getX()+(int)(Settings.THICK/2), dots.get(i).getY()+(int)(Settings.THICK/2));
g2d.dispose();
}
else{
switch(Settings.STYLE){
case 0: g.fillRect(dots.get(i).getX(), dots.get(i).getY(), Settings.THICK, Settings.THICK);
break;
case 1: g.fillOval(dots.get(i).getX(), dots.get(i).getY(), Settings.THICK, Settings.THICK);
break;
default: g.fillRect(dots.get(i).getX(), dots.get(i).getY(), Settings.THICK, Settings.THICK);
break;
}
}
}
else{
switch(Settings.STYLE){
case 0: g.fillRect(dots.get(i).getX(), dots.get(i).getY(), Settings.THICK, Settings.THICK);
break;
case 1: g.fillOval(dots.get(i).getX(), dots.get(i).getY(), Settings.THICK, Settings.THICK);
break;
default: break;
}
}
prevX = dots.get(i).getX(); prevY = dots.get(i).getY();
}
}
示例8: fac
import java.lang.Math; //導入方法依賴的package包/類
/**
* Fac double.
*
* @param x a double value
* @return the factorial of the argument
* @throws ArithmeticException the arithmetic exception
*/
static public double fac(double x) throws ArithmeticException {
double d = Math.abs(x);
if(Math.floor(d) == d) return (double)fac( (int)x );
else return gamma(x+1.0);
}