List of usage examples for java.math BigDecimal longValue
@Override public long longValue()
From source file:de.csdev.ebus.command.datatypes.std.AbstractEBusTypeUnsignedNumber.java
@Override public byte[] encodeInt(Object data) throws EBusTypeException { BigDecimal b = NumberUtils.toBigDecimal(data == null ? 0 : data); long l = b.longValue() & Long.MAX_VALUE; int length = getTypeLength(); byte[] result = new byte[length]; for (int i = 0; i <= length - 1; i++) { result[i] = (byte) (l & 0xFF); l >>= 8;/*from w w w. j a va 2 s . co m*/ } return result; }
From source file:com.nortal.petit.core.dialect.OracleSqlDialect.java
@SuppressWarnings("unchecked") @Override/* w w w . jav a2s. c om*/ public <B> B insertReturningId(JdbcOperations jdbcOperations, String sql, String idColumn, final Object... params) { final String actualSql = new StringBuilder("BEGIN ").append(sql) .append(" RETURNING " + idColumn + " INTO ?; END;").toString(); try { return (B) jdbcOperations.execute(new CallableStatementCreator() { @Override public CallableStatement createCallableStatement(Connection con) throws SQLException { CallableStatement cs = con.prepareCall(actualSql); ArgPreparedStatementSetter.setValues(cs, params, 1); cs.registerOutParameter(params.length + 1, Types.DECIMAL); return cs; } }, new CallableStatementCallback<B>() { @Override public B doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException { cs.execute(); BigDecimal bd = cs.getBigDecimal(params.length + 1); return (B) Long.valueOf(bd.longValue()); } }); } catch (RuntimeException e) { LOG.error("Error processing SQL '" + sql + "' with parameters: " + StringUtils.join(params, "; ")); throw e; } }
From source file:py.una.pol.karaku.dao.entity.interceptors.BigDecimalInterceptor.java
@Override public void intercept(Operation o, Field field, Object bean) { BigDecimal value = (BigDecimal) ReflectionUtils.getField(field, bean); if (value == null) { return;// w w w . j a va 2 s . c om } if (value.longValue() < 1) { value = value.add(BigDecimal.ONE); } BigDecimal trailed = value.stripTrailingZeros(); int precision = trailed.scale(); if (precision > MAXIMUM_PRECISION) { throw new KarakuRuntimeException( String.format("Attribute '%s' of bean '%s' has a precision of {%d}, maximum allowed is {%d}", field.getName(), bean.getClass().getSimpleName(), precision, MAXIMUM_PRECISION)); } }
From source file:Main.java
/** * Compute e^x to a given scale./* w w w . jav a 2s.com*/ * Break x into its whole and fraction parts and * compute (e^(1 + fraction/whole))^whole using Taylor's formula. * @param x the value of x * @param scale the desired scale of the result * @return the result value */ public static BigDecimal exp(BigDecimal x, int scale) { // e^0 = 1 if (x.signum() == 0) { return BigDecimal.valueOf(1); } // If x is negative, return 1/(e^-x). else if (x.signum() == -1) { return BigDecimal.valueOf(1).divide(exp(x.negate(), scale), scale, BigDecimal.ROUND_HALF_EVEN); } // Compute the whole part of x. BigDecimal xWhole = x.setScale(0, BigDecimal.ROUND_DOWN); // If there isn't a whole part, compute and return e^x. if (xWhole.signum() == 0) return expTaylor(x, scale); // Compute the fraction part of x. BigDecimal xFraction = x.subtract(xWhole); // z = 1 + fraction/whole BigDecimal z = BigDecimal.valueOf(1).add(xFraction.divide(xWhole, scale, BigDecimal.ROUND_HALF_EVEN)); // t = e^z BigDecimal t = expTaylor(z, scale); BigDecimal maxLong = BigDecimal.valueOf(Long.MAX_VALUE); BigDecimal result = BigDecimal.valueOf(1); // Compute and return t^whole using intPower(). // If whole > Long.MAX_VALUE, then first compute products // of e^Long.MAX_VALUE. while (xWhole.compareTo(maxLong) >= 0) { result = result.multiply(intPower(t, Long.MAX_VALUE, scale)).setScale(scale, BigDecimal.ROUND_HALF_EVEN); xWhole = xWhole.subtract(maxLong); Thread.yield(); } return result.multiply(intPower(t, xWhole.longValue(), scale)).setScale(scale, BigDecimal.ROUND_HALF_EVEN); }
From source file:com.sangupta.fileanalysis.db.DBResultViewer.java
private void format(BigDecimal bigDecimal, int size) { format(bigDecimal.longValue(), size); }
From source file:com.norconex.collector.http.data.store.impl.jdbc.JDBCCrawlDataSerializer.java
@Override public ICrawlData toCrawlData(String table, ResultSet rs) throws SQLException { if (rs == null) { return null; }//from www . j a v a 2 s .c om HttpCrawlData data = new HttpCrawlData(); data.setReference(rs.getString("reference")); data.setParentRootReference(rs.getString("parentRootReference")); data.setRootParentReference(rs.getBoolean("isRootParentReference")); data.setState(HttpCrawlState.valueOf(rs.getString("state"))); data.setMetaChecksum(rs.getString("metaChecksum")); data.setDocumentChecksum(rs.getString("contentChecksum")); data.setDepth(rs.getInt("depth")); BigDecimal bigLM = rs.getBigDecimal("sitemapLastMod"); if (bigLM != null) { data.setSitemapLastMod(bigLM.longValue()); } BigDecimal bigP = rs.getBigDecimal("sitemapPriority"); if (bigP != null) { data.setSitemapPriority(bigP.floatValue()); } data.setSitemapChangeFreq(rs.getString("sitemapChangeFreq")); data.setReferrerReference(rs.getString("referrerReference")); data.setReferrerLinkTag(rs.getString("referrerLinkTag")); data.setReferrerLinkText(rs.getString("referrerLinkText")); data.setReferrerLinkTitle(rs.getString("referrerLinkTitle")); return data; }
From source file:org.apache.hadoop.hive.common.type.HiveIntervalDayTime.java
public void set(BigDecimal totalSecondsBd) { long totalSeconds = totalSecondsBd.longValue(); BigDecimal fractionalSecs = totalSecondsBd.remainder(BigDecimal.ONE); int nanos = fractionalSecs.multiply(IntervalDayTimeUtils.NANOS_PER_SEC_BD).intValue(); set(totalSeconds, nanos);/*ww w. j a v a2s. c o m*/ }
From source file:com.sangupta.murmur.MurmurEnglishTest.java
private boolean bigMatch(String actual, String computed) { // try with big decimal try {// w w w. ja v a 2s . c o m BigDecimal in = new BigDecimal(actual); long x = in.longValue(); if (computed.equals(String.valueOf(x))) { return true; } int y = in.intValue(); if (computed.equals(String.valueOf(y))) { return true; } } catch (NumberFormatException e) { System.out.println("actual: " + actual); System.out.println("computed: " + computed); throw new RuntimeException("Failed"); } return false; }
From source file:com.nec.harvest.bean.mapping.PurchaseBean.java
private long bigDecimalToDouble(BigDecimal decimal) { if (decimal == null) { return 0; }/*from w w w .j av a2 s . co m*/ return decimal.longValue(); }
From source file:Main.java
/** * Compute e^x to a given scale. Break x into its whole and fraction parts * and compute (e^(1 + fraction/whole))^whole using Taylor's formula. * /*ww w . j a v a2 s . c o m*/ * @param x * the value of x * @param scale * the desired scale of the result * @return the result value */ public static BigDecimal exp(BigDecimal x, int scale) { // e^0 = 1 if (x.signum() == 0) { return BigDecimal.valueOf(1); } // If x is negative, return 1/(e^-x). else if (x.signum() == -1) { return BigDecimal.valueOf(1).divide(exp(x.negate(), scale), scale, BigDecimal.ROUND_HALF_EVEN); } // Compute the whole part of x. BigDecimal xWhole = x.setScale(0, BigDecimal.ROUND_DOWN); // If there isn't a whole part, compute and return e^x. if (xWhole.signum() == 0) { return expTaylor(x, scale); } // Compute the fraction part of x. BigDecimal xFraction = x.subtract(xWhole); // z = 1 + fraction/whole BigDecimal z = BigDecimal.valueOf(1).add(xFraction.divide(xWhole, scale, BigDecimal.ROUND_HALF_EVEN)); // t = e^z BigDecimal t = expTaylor(z, scale); BigDecimal maxLong = BigDecimal.valueOf(Long.MAX_VALUE); BigDecimal result = BigDecimal.valueOf(1); // Compute and return t^whole using intPower(). // If whole > Long.MAX_VALUE, then first compute products // of e^Long.MAX_VALUE. while (xWhole.compareTo(maxLong) >= 0) { result = result.multiply(intPower(t, Long.MAX_VALUE, scale)).setScale(scale, BigDecimal.ROUND_HALF_EVEN); xWhole = xWhole.subtract(maxLong); Thread.yield(); } return result.multiply(intPower(t, xWhole.longValue(), scale)).setScale(scale, BigDecimal.ROUND_HALF_EVEN); }