List of usage examples for java.lang Math signum
public static float signum(float f)
From source file:ca.zadrox.dota2esportticker.ui.BaseActivity.java
/** * Indicates that the main content has scrolled (for the purposes of showing/hiding * the action bar for the "action bar auto hide" effect). currentY and deltaY may be exact * (if the underlying view supports it) or may be approximate indications: * deltaY may be INT_MAX to mean "scrolled forward indeterminately" and INT_MIN to mean * "scrolled backward indeterminately". currentY may be 0 to mean "somewhere close to the * start of the list" and INT_MAX to mean "we don't know, but not at the start of the list" *//*w w w . jav a2 s . co m*/ private void onMainContentScrolled(int currentY, int deltaY) { if (deltaY > mActionBarAutoHideSensitivity) { deltaY = mActionBarAutoHideSensitivity; } else if (deltaY < -mActionBarAutoHideSensitivity) { deltaY = -mActionBarAutoHideSensitivity; } if (Math.signum(deltaY) * Math.signum(mActionBarAutoHideSignal) < 0) { // deltaY is a motion opposite to the accumulated signal, so reset signal mActionBarAutoHideSignal = deltaY; } else { // add to accumulated signal mActionBarAutoHideSignal += deltaY; } boolean shouldShow = currentY < mActionBarAutoHideMinY || (mActionBarAutoHideSignal <= -mActionBarAutoHideSensitivity); autoShowOrHideActionBar(shouldShow); }
From source file:com.opengamma.analytics.financial.model.volatility.BlackScholesFormulaRepository.java
/** * The spot gamma, 2nd order sensitivity of the spot option value to the spot. <p> * $\frac{\partial^2 FV}{\partial^2 f}$//from ww w.j a v a2 s . c o m * @param spot The spot value of the underlying * @param strike The Strike * @param timeToExpiry The time-to-expiry * @param lognormalVol The log-normal volatility * @param interestRate The interest rate * @param costOfCarry The cost-of-carry rate * @return The spot gamma */ @ExternalFunction public static double gamma(final double spot, final double strike, final double timeToExpiry, final double lognormalVol, final double interestRate, final double costOfCarry) { ArgumentChecker.isTrue(spot >= 0.0, "negative/NaN spot; have {}", spot); ArgumentChecker.isTrue(strike >= 0.0, "negative/NaN strike; have {}", strike); ArgumentChecker.isTrue(timeToExpiry >= 0.0, "negative/NaN timeToExpiry; have {}", timeToExpiry); ArgumentChecker.isTrue(lognormalVol >= 0.0, "negative/NaN lognormalVol; have {}", lognormalVol); ArgumentChecker.isFalse(Double.isNaN(interestRate), "interestRate is NaN"); ArgumentChecker.isFalse(Double.isNaN(costOfCarry), "costOfCarry is NaN"); double coef = 0.; if ((interestRate > LARGE && costOfCarry > LARGE) || (-interestRate > LARGE && -costOfCarry > LARGE) || Math.abs(costOfCarry - interestRate) < SMALL) { coef = 1.; //ref value is returned } else { final double rate = costOfCarry - interestRate; if (rate > LARGE) { return costOfCarry > LARGE ? 0. : Double.POSITIVE_INFINITY; } if (-rate > LARGE) { return 0.; } coef = Math.exp(rate * timeToExpiry); } final double rootT = Math.sqrt(timeToExpiry); double sigmaRootT = lognormalVol * rootT; if (Double.isNaN(sigmaRootT)) { sigmaRootT = 1.; //ref value is returned } if (spot > LARGE * strike || spot < SMALL * strike || sigmaRootT > LARGE) { return 0.; } double factor = Math.exp(costOfCarry * timeToExpiry); if (Double.isNaN(factor)) { factor = 1.; //ref value is returned } double d1 = 0.; if (Math.abs(spot - strike) < SMALL || (spot > LARGE && strike > LARGE)) { final double coefD1 = (Math.abs(costOfCarry) < SMALL && lognormalVol < SMALL) ? Math.signum(costOfCarry) + 0.5 * lognormalVol : (costOfCarry / lognormalVol + 0.5 * lognormalVol); final double tmp = coefD1 * rootT; d1 = Double.isNaN(tmp) ? 0. : tmp; } else { if (sigmaRootT < SMALL) { final double scnd = (Math.abs(costOfCarry) > LARGE && rootT < SMALL) ? Math.signum(costOfCarry) : costOfCarry * rootT; final double tmp = (Math.log(spot / strike) / rootT + scnd) / lognormalVol; d1 = Double.isNaN(tmp) ? 0. : tmp; } else { final double tmp = costOfCarry * rootT / lognormalVol; final double sig = (costOfCarry >= 0.) ? 1. : -1.; final double scnd = Double.isNaN(tmp) ? ((lognormalVol < LARGE && lognormalVol > SMALL) ? sig / lognormalVol : sig * rootT) : tmp; d1 = Math.log(spot / strike) / sigmaRootT + scnd + 0.5 * sigmaRootT; } } // if (Double.isNaN(d1)) { // throw new IllegalArgumentException("NaN found"); // } final double norm = NORMAL.getPDF(d1); final double res = norm < SMALL ? 0. : coef * norm / spot / sigmaRootT; return Double.isNaN(res) ? Double.POSITIVE_INFINITY : res; }
From source file:org.janusgraph.graphdb.serializer.SerializerTest.java
License:asdf
@Test public void testSerializedOrder() { serialize.registerClass(1, TClass1.class, new TClass1Serializer()); final Map<Class, Factory> sortTypes = new HashMap<>(); for (Map.Entry<Class, Factory> entry : TYPES.entrySet()) { if (serialize.isOrderPreservingDatatype(entry.getKey())) sortTypes.put(entry.getKey(), entry.getValue()); }//from w w w. j a va2s . co m assertEquals(10, sortTypes.size()); for (int t = 0; t < 3000000; t++) { DataOutput o1 = serialize.getDataOutput(64); DataOutput o2 = serialize.getDataOutput(64); Map.Entry<Class, Factory> type = Iterables.get(sortTypes.entrySet(), random.nextInt(sortTypes.size())); Comparable c1 = (Comparable) type.getValue().newInstance(); Comparable c2 = (Comparable) type.getValue().newInstance(); o1.writeObjectByteOrder(c1, type.getKey()); o2.writeObjectByteOrder(c2, type.getKey()); StaticBuffer s1 = o1.getStaticBuffer(); StaticBuffer s2 = o2.getStaticBuffer(); assertEquals(Math.signum(c1.compareTo(c2)), Math.signum(s1.compareTo(s2)), 0.0); Object c1o = serialize.readObjectByteOrder(s1.asReadBuffer(), type.getKey()); Object c2o = serialize.readObjectByteOrder(s2.asReadBuffer(), type.getKey()); assertEquals(c1, c1o); assertEquals(c2, c2o); } }
From source file:com.nononsenseapps.feeder.ui.BaseActivity.java
/** * Indicates that the main content has scrolled (for the purposes of * showing/hiding/*from w w w . j ava 2s . co m*/ * the action bar for the "action bar auto hide" effect). currentY and * deltaY may be exact * (if the underlying view supports it) or may be approximate indications: * deltaY may be INT_MAX to mean "scrolled forward indeterminately" and * INT_MIN to mean * "scrolled backward indeterminately". currentY may be 0 to mean * "somewhere close to the * start of the list" and INT_MAX to mean "we don't know, but not at the * start of the list" */ private void onMainContentScrolled(int currentY, int deltaY, boolean force) { if (deltaY > mActionBarAutoHideSensivity) { deltaY = mActionBarAutoHideSensivity; } else if (deltaY < -mActionBarAutoHideSensivity) { deltaY = -mActionBarAutoHideSensivity; } if (Math.signum(deltaY) * Math.signum(mActionBarAutoHideSignal) < 0) { // deltaY is a motion opposite to the accumulated signal, so reset signal mActionBarAutoHideSignal = deltaY; } else { // add to accumulated signal mActionBarAutoHideSignal += deltaY; } boolean shouldShow = currentY < mActionBarAutoHideMinY || (mActionBarAutoHideSignal <= -mActionBarAutoHideSensivity); autoShowOrHideActionBar(shouldShow | force); }
From source file:it.tidalwave.northernwind.frontend.ui.component.blog.DefaultBlogViewController.java
/******************************************************************************************************************* * * ******************************************************************************************************************/ private void computeRanks(final @Nonnull Collection<TagAndCount> tagsAndCount) { final List<TagAndCount> tagsAndCountByCountDescending = new ArrayList<>(tagsAndCount); Collections.sort(tagsAndCountByCountDescending, new Comparator<TagAndCount>() { @Override//from ww w .ja va 2 s . c om public int compare(final @Nonnull TagAndCount tac1, final @Nonnull TagAndCount tac2) { return (int) Math.signum(tac2.count - tac1.count); } }); int rank = 1; int previousCount = 0; for (final TagAndCount tac : tagsAndCountByCountDescending) { tac.rank = (rank <= 10) ? Integer.toString(rank) : "Others"; if (previousCount != tac.count) { rank++; } previousCount = tac.count; } }
From source file:com.etmay.brescrollpager.ui.MyScroller.java
/** * @hide/* www .j a v a 2 s .c o m*/ */ public boolean isScrollingInDirection(float xvel, float yvel) { return !mFinished && Math.signum(xvel) == Math.signum(mFinalX - mStartX) && Math.signum(yvel) == Math.signum(mFinalY - mStartY); }
From source file:org.nd4j.linalg.cpu.complex.ComplexFloat.java
@Override public ComplexFloat sqrt() { float a = absoluteValue(); float s2 = (float) Math.sqrt(2); float p = (float) Math.sqrt(a + realComponent()) / s2; float q = (float) Math.sqrt(a - realComponent()) / s2 * Math.signum(imaginaryComponent()); return new ComplexFloat(p, q); }
From source file:org.nd4j.linalg.cpu.complex.ComplexDouble.java
@Override public ComplexDouble sqrt() { double a = absoluteValue(); double s2 = Math.sqrt(2); double p = Math.sqrt(a + realComponent()) / s2; double q = Math.sqrt(a - realComponent()) / s2 * Math.signum(imaginaryComponent()); return new ComplexDouble(p, q); }
From source file:com.opengamma.analytics.financial.model.volatility.BlackScholesFormulaRepository.java
/** * The dual gamma//from w ww . j a v a2 s . c o m * @param spot The spot value of the underlying * @param strike The Strike * @param timeToExpiry The time-to-expiry * @param lognormalVol The log-normal volatility * @param interestRate The interest rate * @param costOfCarry The cost-of-carry rate * @return The dual gamma */ @ExternalFunction public static double dualGamma(final double spot, final double strike, final double timeToExpiry, final double lognormalVol, final double interestRate, final double costOfCarry) { ArgumentChecker.isTrue(spot >= 0.0, "negative/NaN spot; have {}", spot); ArgumentChecker.isTrue(strike >= 0.0, "negative/NaN strike; have {}", strike); ArgumentChecker.isTrue(timeToExpiry >= 0.0, "negative/NaN timeToExpiry; have {}", timeToExpiry); ArgumentChecker.isTrue(lognormalVol >= 0.0, "negative/NaN lognormalVol; have {}", lognormalVol); ArgumentChecker.isFalse(Double.isNaN(interestRate), "interestRate is NaN"); ArgumentChecker.isFalse(Double.isNaN(costOfCarry), "costOfCarry is NaN"); if (-interestRate > LARGE) { return costOfCarry > LARGE ? 0. : Double.POSITIVE_INFINITY; } if (interestRate > LARGE) { return 0.; } double discount = (Math.abs(interestRate) < SMALL && timeToExpiry > LARGE) ? 1. : Math.exp(-interestRate * timeToExpiry); final double rootT = Math.sqrt(timeToExpiry); double sigmaRootT = lognormalVol * rootT; if (Double.isNaN(sigmaRootT)) { sigmaRootT = 1.; //ref value is returned } if (spot > LARGE * strike || spot < SMALL * strike || sigmaRootT > LARGE) { return 0.; } double factor = Math.exp(costOfCarry * timeToExpiry); if (Double.isNaN(factor)) { factor = 1.; } double d2 = 0.; if (Math.abs(spot - strike) < SMALL || (spot > LARGE && strike > LARGE)) { final double coefD1 = (Math.abs(costOfCarry) < SMALL && lognormalVol < SMALL) ? Math.signum(costOfCarry) - 0.5 * lognormalVol : (costOfCarry / lognormalVol - 0.5 * lognormalVol); final double tmp = coefD1 * rootT; d2 = Double.isNaN(tmp) ? 0. : tmp; } else { if (sigmaRootT < SMALL) { final double scnd = (Math.abs(costOfCarry) > LARGE && rootT < SMALL) ? Math.signum(costOfCarry) : costOfCarry * rootT; final double tmp = (Math.log(spot / strike) / rootT + scnd) / lognormalVol; d2 = Double.isNaN(tmp) ? 0. : tmp; } else { final double tmp = costOfCarry * rootT / lognormalVol; final double sig = (costOfCarry >= 0.) ? 1. : -1.; final double scnd = Double.isNaN(tmp) ? ((lognormalVol < LARGE && lognormalVol > SMALL) ? sig / lognormalVol : sig * rootT) : tmp; d2 = Math.log(spot / strike) / sigmaRootT + scnd - 0.5 * sigmaRootT; } } // if (Double.isNaN(d2)) { // throw new IllegalArgumentException("NaN found"); // } final double norm = NORMAL.getPDF(d2); final double res = norm < SMALL ? 0. : discount * norm / strike / sigmaRootT; return Double.isNaN(res) ? Double.POSITIVE_INFINITY : res; }
From source file:edu.tum.cs.vis.model.util.algorithm.ACCUM.java
/** * Calculate hue and saturation for curvature properties. * //from w w w .j a va 2s . c om * @param curvatures * maps curvatures to vertices * @param smoothSigma * Sigma value for smoothing the curvature. Set to 0 to disable smoothing. * @param m * model needed to calculate hue saturation scale */ private static void setCurvatureHueSaturation(HashMap<Vertex, Curvature> curvatures, Model m, float smoothSigma) { if (smoothSigma > 0.0f) { float scaledSigma = smoothSigma * m.feature_size(); diffuse_curv(m, curvatures, scaledSigma); } float cscale = 120.0f * typical_scale(curvatures, m); cscale = cscale * cscale; int nv = m.getVertices().size(); for (int i = 0; i < nv; i++) { Curvature c = curvatures.get(m.getVertices().get(i)); float H = 0.5f * (c.getCurvatureMax() + c.getCurvatureMin()); // mean curvature float K = c.getCurvatureMax() * c.getCurvatureMin(); // gaussian curvature float h = (float) (4.0f / 3.0f * Math.abs(Math.atan2(H * H - K, H * H * Math.signum(H)))); float s = (float) ((2 / Math.PI) * Math.atan((2.0f * H * H - K) * cscale)); c.setHue(h); c.setSaturation(s); } }