Example usage for java.lang Math signum

List of usage examples for java.lang Math signum

Introduction

In this page you can find the example usage for java.lang Math signum.

Prototype

public static float signum(float f) 

Source Link

Document

Returns the signum function of the argument; zero if the argument is zero, 1.0f if the argument is greater than zero, -1.0f if the argument is less than zero.

Usage

From source file:com.capitati.omtc.core.negotiation.SemanticVersionComparator.java

public static final ImmutablePair<Integer, SemanticVersionComponent> compare(final ISemanticVersion verOne,
        final ISemanticVersion verTwo) {
    if (verOne.equals(verTwo) == true) {
        return new ImmutablePair<Integer, SemanticVersionComponent>(0, SemanticVersionComponent.INVALID);
    }//from w w  w .  j  av a  2s.  c o  m

    if (verOne.getMajor() == verTwo.getMajor()) {
        if (verOne.getMinor() == verTwo.getMinor()) {
            if (verOne.getPatch() == verTwo.getPatch()) {
                /*
                 * Compare the pre-release components.
                 */
                final ImmutablePair<Integer, Boolean> preReleaseCompResult = compareArray(
                        verOne.getPreRelease(), verTwo.getPreRelease());
                /*
                 * Compare the build components.
                 */
                final ImmutablePair<Integer, Boolean> buildCompResult = compareArray(verOne.getBuild(),
                        verTwo.getBuild());

                /*
                 * Unpack the comparison values.
                 */
                final int prc = preReleaseCompResult.getLeft();
                final int bc = buildCompResult.getLeft();

                if ((preReleaseCompResult.getRight() == true) && (buildCompResult.getRight() == true)) {
                    /*
                     * There was at most one pre-release component, and at most one
                     * build component in both versions.
                     */
                    if ((Math.abs(prc) == 1) && (Math.abs(bc) == 1)) {
                        return new ImmutablePair<Integer, SemanticVersionComponent>(
                                (Math.signum((float) prc) == 1.0) ? -1 : 1,
                                SemanticVersionComponent.PRE_RELEASE_AND_BUILD_VERSION);
                    } else if ((Math.abs(prc) == 1) && (bc == 0)) {
                        return new ImmutablePair<Integer, SemanticVersionComponent>(
                                (Math.signum((float) prc) == 1.0) ? -1 : 1,
                                SemanticVersionComponent.PRE_RELEASE_AND_BUILD_VERSION);
                    }

                    return new ImmutablePair<Integer, SemanticVersionComponent>(bc,
                            SemanticVersionComponent.PRE_RELEASE_AND_BUILD_VERSION);
                } else if ((preReleaseCompResult.getRight() == true) && (buildCompResult.getRight() == false)) {
                    /*
                     * One of the versions had a null pre-release.
                     */
                    return new ImmutablePair<Integer, SemanticVersionComponent>(bc,
                            SemanticVersionComponent.PRE_RELEASE_AND_BUILD_VERSION);
                }

                /*
                 * Either one of the version has a null build or both versions where
                 * fully specified.
                 */
                return new ImmutablePair<Integer, SemanticVersionComponent>((Math.abs(prc) == 1) ? prc : bc,
                        SemanticVersionComponent.PRE_RELEASE_AND_BUILD_VERSION);
            } else {
                return new ImmutablePair<Integer, SemanticVersionComponent>(
                        verOne.getPatch() - verTwo.getPatch(), SemanticVersionComponent.PATCH_VERSION);
            }
        } else {
            return new ImmutablePair<Integer, SemanticVersionComponent>(verOne.getMinor() - verTwo.getMinor(),
                    SemanticVersionComponent.MINOR_VERSION);
        }
    }

    return new ImmutablePair<Integer, SemanticVersionComponent>(verOne.getMajor() - verTwo.getMajor(),
            SemanticVersionComponent.MAJOR_VERSION);
}

From source file:edu.emory.mathcs.nlp.common.util.MathUtils.java

static public int signum(double d) {
    return (int) Math.signum(d);
}

From source file:com.opengamma.analytics.math.statistics.distribution.LaplaceDistribution.java

/**
 * {@inheritDoc}/*from w  w  w .j  a  v a2s . com*/
 */
@Override
public double getCDF(final Double x) {
    Validate.notNull(x);
    return 0.5 * (1 + Math.signum(x - _mu) * (1 - Math.exp(-Math.abs(x - _mu) / _b)));
}

From source file:com.google.android.apps.santatracker.doodles.tilt.StickyActor.java

/**
 * Cause the other actor to be slowed down by this actor.
 *///  w  ww .  java 2s.com
@Override
public boolean resolveCollision(Actor other, float deltaMs) {
    if (!isEnabled || other.velocity.getLength() == 0 || !collisionBody.contains(other.position)) {
        // Don't bother resolving the collision if the other actor is either not moving, or if the
        // other actor is not colliding with this object.
        return false;
    }
    float deltaSeconds = deltaMs / 1000.0f;
    Vector2D acceleration = Vector2D.get(other.velocity).normalize();
    if (other.velocity.getLength() < 400) {
        acceleration.scale(0.01f * stickiness * Constants.GRAVITY);
    } else {
        acceleration.scale(stickiness * Constants.GRAVITY);
    }
    if (Math.signum(other.velocity.x - acceleration.x * deltaSeconds) != Math.signum(other.velocity.x)) {
        // Don't allow stickiness to accelerate the ball in the other direction.
        other.velocity.x = 0;
        other.velocity.y = 0;
    } else {
        other.velocity.x -= acceleration.x * deltaSeconds;
        other.velocity.y -= acceleration.y * deltaSeconds;
    }
    return false;
}

From source file:at.meikel.dmrl.webapp.rest.PlayerService.java

@RequestMapping(value = { "/playersByTeam/{teamName}" }, method = RequestMethod.GET)
@ResponseBody//from www .j  a v a 2 s.  c  o m
public List<Player> getPlayersByTeam(@PathVariable String teamName) {
    List<Player> result = null;
    if (server != null) {
        result = server.getRankingList().find(teamName);
    }

    if (result == null) {
        result = new Vector<Player>();
    }

    Collections.sort(result, new Comparator<Player>() {
        @Override
        public int compare(Player p1, Player p2) {
            if (p1 == null) {
                return p2 == null ? 0 : 1;
            } else {
                if (p2 == null) {
                    return -1;
                } else {
                    return (int) Math.signum(p1.getRanglistenwert() - p2.getRanglistenwert());
                }
            }
        }
    });

    return result;
}

From source file:com.github.riccardove.easyjasub.commandline.CommandLineOptionList.java

public void printHelp(PrintWriter stream, String usage, String header, String footer) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setOptionComparator(new Comparator<Option>() {
        @Override/*from w w w .ja v a2 s . com*/
        public int compare(Option opt1, Option opt2) {
            return (int) Math.signum(optionsOrder.get(opt1.getOpt()) - optionsOrder.get(opt2.getOpt()));
        }
    });
    formatter.printHelp(stream, HelpFormatter.DEFAULT_WIDTH, usage, header, options,
            HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, footer);
}

From source file:com.opengamma.analytics.math.statistics.distribution.LaplaceDistribution.java

/**
 * {@inheritDoc}/*from  w  w w.ja v a  2 s  .co  m*/
 */
@Override
public double getInverseCDF(final Double p) {
    Validate.notNull(p);
    Validate.isTrue(p >= 0 && p <= 1, "Probability must lie between 0 and 1 (inclusive)");
    return _mu - _b * Math.signum(p - 0.5) * Math.log(1 - 2 * Math.abs(p - 0.5));
}

From source file:org.apache.tajo.rule.base.CheckHadoopRuntimeVersionRule.java

private int compareVersion(int[] left, int[] right) {
    int returnValue = 0;
    int minLength = Math.min(left.length, right.length);

    for (int idx = 0; idx < minLength; idx++) {
        returnValue = (int) Math.signum(left[idx] - right[idx]);
        if (returnValue != 0) {
            break;
        }//  w  w  w .  j a v a  2 s.c o m
    }

    if (returnValue == 0) {
        returnValue = (int) Math.signum(left.length - right.length);
    }
    return returnValue;
}

From source file:com.opengamma.analytics.financial.interestrate.payments.method.CouponFixedAccruedCompoundingDiscountingMethod.java

/**
 * Computes the present value of the fixed coupon with positive notional (abs(notional) is used) by discounting.
 * @param cpn The coupon.//from www  . j a va2 s . co m
 * @param curves The curve bundle.
 * @return The present value.
 */
public CurrencyAmount presentValuePositiveNotional(final CouponFixedAccruedCompounding cpn,
        final YieldCurveBundle curves) {
    Validate.notNull(curves);
    Validate.notNull(cpn);
    return CurrencyAmount.of(cpn.getCurrency(),
            Math.signum(cpn.getNotional()) * presentValue(cpn, curves).getAmount());
}

From source file:gedi.util.math.stat.testing.MantelHaenszelTest.java

/**
 * Returns this!/*  w w w. ja v  a  2  s  .c o  m*/
 * @param table
 * @return
 * @throws MathException
 */
public MantelHaenszelTest compute(TwoByTwoByKTable table) {
    this.table = table;

    double delta = table.getDelta();
    double yates = correct && (delta >= 0.5) ? 0.5 : 0;
    double deltayates = delta - yates;
    stat = deltayates * deltayates / table.getVarianceEstimate();

    if (h1 == H1.NOT_EQUAL)
        pval = stat > 30 ? 0 : (1 - chisq.cumulativeProbability(stat));
    else if (h1 == H1.LESS_THAN)
        pval = norm.cumulativeProbability(Math.signum(delta) * Math.sqrt(stat));
    else
        pval = 1 - norm.cumulativeProbability(Math.signum(delta) * Math.sqrt(stat));

    estimate = table.getOddsRatio();
    double sd = table.computeSD();

    if (h1 == H1.LESS_THAN) {
        lowerConf = 0;
        upperConf = estimate * Math.exp(norm.inverseCumulativeProbability(confLevel) * sd);
    } else if (h1 == H1.GREATER_THAN) {
        lowerConf = estimate * Math.exp(norm.inverseCumulativeProbability(1 - confLevel) * sd);
        upperConf = Double.POSITIVE_INFINITY;
    } else {
        lowerConf = estimate * Math.exp(norm.inverseCumulativeProbability((1 - confLevel) / 2) * sd);
        upperConf = estimate * Math.exp(-norm.inverseCumulativeProbability((1 - confLevel) / 2) * sd);
    }
    return this;
}