本文整理汇总了Java中java.math.BigInteger.doubleValue方法的典型用法代码示例。如果您正苦于以下问题:Java BigInteger.doubleValue方法的具体用法?Java BigInteger.doubleValue怎么用?Java BigInteger.doubleValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.math.BigInteger
的用法示例。
在下文中一共展示了BigInteger.doubleValue方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nRoot
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Returns the Nth root implemented by the formula from <a href="https://en.wikipedia.org/wiki/Nth_root"> wikipedia</a>.
*
* @author AdamKuba
* @param n degree
* @param a radicand
* @return nth root of the radicand
*/
public static BigDecimal nRoot(BigInteger n, BigDecimal a) {
boolean signed = false;
if (n.doubleValue()<0){
n = n.negate();
signed = true;
}
if(signed && a.doubleValue()<0){
return new BigDecimal("-1");
}
double p = 0.00000000001;
BigDecimal prev=a;
BigDecimal next=a.divide(new BigDecimal(n),15, RoundingMode.HALF_UP);
while(abs(prev.subtract(next)).doubleValue()>p){
prev = next;
next = (new BigDecimal(n.subtract(new BigInteger("1"))).multiply(prev).add(a.divide(exp(n.subtract(new BigInteger("1")),prev),15, RoundingMode.HALF_UP))).divide(new BigDecimal(n),15, RoundingMode.HALF_UP);
}
if (signed) next = new BigDecimal("1").divide(next,15, RoundingMode.HALF_UP);
next = next.round(new MathContext(10));
return next;
}
示例2: convertToOrder
import java.math.BigInteger; //导入方法依赖的package包/类
private Order convertToOrder(List<Type> list) {
Order order = null;
if (null != list && list.size() > 0) {
BigInteger quantity = ((Uint256) list.get(0)).getValue();
BigInteger price = ((Uint256) list.get(1)).getValue();
Boolean buy = ((Bool) list.get(2)).getValue();
String ownerAddress = ((Address) list.get(3)).toString();
BigInteger dealNr = ((Uint256) list.get(4)).getValue();
BigInteger extId = ((Uint256) list.get(5)).getValue();
Order.Type type = Order.Type.BUY;
if (!buy) {
type = Order.Type.SELL;
}
order = new Order(type, quantity.intValue(), price.doubleValue() / 100, extId.intValue());
order.setId(dealNr.intValue());
order.setOwner(ownerAddress);
}
return order;
}
示例3: MFPNumeric
import java.math.BigInteger; //导入方法依赖的package包/类
public MFPNumeric(BigInteger bigIntValue) {
mlValue = bigIntValue.longValue();
int nComparelValue = bigIntValue.compareTo(BigInteger.valueOf(mlValue));
if (nComparelValue > 0) {
mlValue = Long.MAX_VALUE; // means long overflowed.
} else if (nComparelValue < 0) {
mlValue = Long.MIN_VALUE; // means long overflowed.
}
mdValue = bigIntValue.doubleValue();
mbigIntegerValue = bigIntValue;
mbigDecimalValue = new BigDecimal(bigIntValue);
mType = Type.MFP_INTEGER_VALUE;
// now let's check if this MFPNumeric is an integer and compare it with 0.
mbIsActuallyInteger = true;
mdActualValueCompZero = bigIntValue.compareTo(BigInteger.ZERO);
}
示例4: transform
import java.math.BigInteger; //导入方法依赖的package包/类
public String transform(PropertyValue value, String result) {
double floatValue;
if (value.getLSB() != null) {
BigInteger val = parse(value, result);
if (!value.mask().equals(BigInteger.ZERO))
val = val.and(value.mask());
if (!value.shift().equals(0))
val = val.shiftRight(value.shift());
if (value.getSigned() && val.bitLength()==(value.size()*4)) {
BigInteger complement = new BigInteger(new String(new char[value.size()]).replace("\0", "F"),16);
val = val.subtract(complement);
}
if (!objectCache.getTransformData()) {
int intValue = val.intValue();
return String.valueOf(intValue);
}
floatValue = val.doubleValue();
} else {
floatValue = Float.parseFloat(result);
}
if (!value.base().equals(0))
floatValue = Math.pow(value.base(), floatValue);
floatValue = floatValue * value.scale();
floatValue = floatValue + value.offset();
if (value.getType().toLowerCase().equals("f") || value.getType().toLowerCase().equals("float"))
return String.valueOf(floatValue);
return String.valueOf(Math.round(floatValue));
}
示例5: TODO
import java.math.BigInteger; //导入方法依赖的package包/类
@AndroidIncompatible // TODO(cpovirk): File bug for BigDecimal.doubleValue().
public void testBigToDouble() {
for (BigInteger b : ALL_BIGINTEGER_CANDIDATES) {
if (b.doubleValue() != DoubleUtils.bigToDouble(b)) {
failFormat(
"Converting %s to double: expected doubleValue %s but got bigToDouble %s",
b,
b.doubleValue(),
DoubleUtils.bigToDouble(b));
}
}
}
示例6: testDoubleValue
import java.math.BigInteger; //导入方法依赖的package包/类
public static int testDoubleValue() {
int failures = 0;
for (BigInteger big : ALL_BIGINTEGER_CANDIDATES) {
double expected = Double.parseDouble(big.toString());
double actual = big.doubleValue();
// should be bitwise identical
if (Double.doubleToRawLongBits(expected) != Double
.doubleToRawLongBits(actual)) {
System.out.println(big);
failures++;
}
}
return failures;
}
示例7: getNativeDouble
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Get the value of a column in the current row as a Java double.
*
* @param columnIndex
* the first column is 1, the second is 2,...
*
* @return the column value; 0 if SQL NULL
*
* @exception SQLException
* if a database access error occurs
*/
protected double getNativeDouble(int columnIndex) throws SQLException {
checkRowPos();
checkColumnBounds(columnIndex);
columnIndex--; // / JDBC is 1-based
if (this.thisRow.isNull(columnIndex)) {
this.wasNullFlag = true;
return 0;
}
this.wasNullFlag = false;
Field f = this.fields[columnIndex];
switch (f.getMysqlType()) {
case MysqlDefs.FIELD_TYPE_DOUBLE:
return this.thisRow.getNativeDouble(columnIndex);
case MysqlDefs.FIELD_TYPE_TINY:
if (!f.isUnsigned()) {
return getNativeByte(columnIndex + 1);
}
return getNativeShort(columnIndex + 1);
case MysqlDefs.FIELD_TYPE_SHORT:
case MysqlDefs.FIELD_TYPE_YEAR:
if (!f.isUnsigned()) {
return getNativeShort(columnIndex + 1);
}
return getNativeInt(columnIndex + 1);
case MysqlDefs.FIELD_TYPE_INT24:
case MysqlDefs.FIELD_TYPE_LONG:
if (!f.isUnsigned()) {
return getNativeInt(columnIndex + 1);
}
return getNativeLong(columnIndex + 1);
case MysqlDefs.FIELD_TYPE_LONGLONG:
long valueAsLong = getNativeLong(columnIndex + 1);
if (!f.isUnsigned()) {
return valueAsLong;
}
BigInteger asBigInt = convertLongToUlong(valueAsLong);
// TODO: Check for overflow
return asBigInt.doubleValue();
case MysqlDefs.FIELD_TYPE_FLOAT:
return getNativeFloat(columnIndex + 1);
case MysqlDefs.FIELD_TYPE_BIT:
return getNumericRepresentationOfSQLBitType(columnIndex + 1);
default:
String stringVal = getNativeString(columnIndex + 1);
if (this.useUsageAdvisor) {
issueConversionViaParsingWarning("getDouble()", columnIndex, stringVal, this.fields[columnIndex],
new int[] { MysqlDefs.FIELD_TYPE_DOUBLE, MysqlDefs.FIELD_TYPE_TINY, MysqlDefs.FIELD_TYPE_SHORT, MysqlDefs.FIELD_TYPE_LONG,
MysqlDefs.FIELD_TYPE_LONGLONG, MysqlDefs.FIELD_TYPE_FLOAT });
}
return getDoubleFromString(stringVal, columnIndex + 1);
}
}
示例8: transform
import java.math.BigInteger; //导入方法依赖的package包/类
public String transform(PropertyValue value, String result) {
double floatValue;
if (value.getType().toLowerCase().equals("s")
|| value.getType().toLowerCase().equals("string")) {
return result;
}
if (value.getLSB() != null) {
BigInteger val = parse(value, result);
if (!value.mask().equals(BigInteger.ZERO)) {
val = val.and(value.mask());
}
if (!value.shift().equals(0)) {
val = val.shiftRight(value.shift());
}
if (value.getSigned() && val.bitLength() == (value.size() * 4)) {
BigInteger complement =
new BigInteger(new String(new char[value.size()]).replace("\0", "F"), 16);
val = val.subtract(complement);
}
if (!objectCache.getTransformData()) {
int intValue = val.intValue();
return String.valueOf(intValue);
}
floatValue = val.doubleValue();
} else {
floatValue = Float.parseFloat(result);
}
if (!value.base().equals(0)) {
floatValue = Math.pow(value.base(), floatValue);
}
floatValue = floatValue * value.scale();
floatValue = floatValue + value.offset();
if (value.getType().toLowerCase().equals("f")
|| value.getType().toLowerCase().equals("float")) {
return String.valueOf(floatValue);
}
return String.valueOf(Math.round(floatValue));
}
示例9: getNativeDouble
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Get the value of a column in the current row as a Java double.
*
* @param columnIndex
* the first column is 1, the second is 2,...
*
* @return the column value; 0 if SQL NULL
*
* @exception SQLException
* if a database access error occurs
*/
protected double getNativeDouble(int columnIndex) throws SQLException {
checkRowPos();
checkColumnBounds(columnIndex);
columnIndex--; // / JDBC is 1-based
if (this.thisRow.isNull(columnIndex)) {
this.wasNullFlag = true;
return 0;
}
this.wasNullFlag = false;
Field f = this.fields[columnIndex];
switch (f.getMysqlType()) {
case MysqlDefs.FIELD_TYPE_DOUBLE:
return this.thisRow.getNativeDouble(columnIndex);
case MysqlDefs.FIELD_TYPE_TINY:
if (!f.isUnsigned()) {
return getNativeByte(columnIndex + 1);
}
return getNativeShort(columnIndex + 1);
case MysqlDefs.FIELD_TYPE_SHORT:
case MysqlDefs.FIELD_TYPE_YEAR:
if (!f.isUnsigned()) {
return getNativeShort(columnIndex + 1);
}
return getNativeInt(columnIndex + 1);
case MysqlDefs.FIELD_TYPE_INT24:
case MysqlDefs.FIELD_TYPE_LONG:
if (!f.isUnsigned()) {
return getNativeInt(columnIndex + 1);
}
return getNativeLong(columnIndex + 1);
case MysqlDefs.FIELD_TYPE_LONGLONG:
long valueAsLong = getNativeLong(columnIndex + 1);
if (!f.isUnsigned()) {
return valueAsLong;
}
BigInteger asBigInt = convertLongToUlong(valueAsLong);
// TODO: Check for overflow
return asBigInt.doubleValue();
case MysqlDefs.FIELD_TYPE_FLOAT:
return getNativeFloat(columnIndex + 1);
case MysqlDefs.FIELD_TYPE_BIT:
return getNumericRepresentationOfSQLBitType(columnIndex + 1);
default:
String stringVal = getNativeString(columnIndex + 1);
if (this.useUsageAdvisor) {
issueConversionViaParsingWarning("getDouble()", columnIndex, stringVal, this.fields[columnIndex], new int[] { MysqlDefs.FIELD_TYPE_DOUBLE,
MysqlDefs.FIELD_TYPE_TINY, MysqlDefs.FIELD_TYPE_SHORT, MysqlDefs.FIELD_TYPE_LONG, MysqlDefs.FIELD_TYPE_LONGLONG,
MysqlDefs.FIELD_TYPE_FLOAT });
}
return getDoubleFromString(stringVal, columnIndex + 1);
}
}
示例10: transform
import java.math.BigInteger; //导入方法依赖的package包/类
public String transform(PropertyValue value, String result) {
double floatValue;
// Do not perform transforms on non-numeric fields
if (nonNumeric(value)) {
return result;
}
if (value.getLSB() != null) {
BigInteger val = parse(value, result);
if (!value.mask().equals(BigInteger.ZERO)) {
val = val.and(value.mask());
}
if (!value.shift().equals(0)) {
val = val.shiftRight(value.shift());
}
if (value.getSigned() && val.bitLength() == (value.size() * 4)) {
BigInteger complement =
new BigInteger(new String(new char[value.size()]).replace("\0", "F"), 16);
val = val.subtract(complement);
}
if (!objectCache.getTransformData()) {
int intValue = val.intValue();
return String.valueOf(intValue);
}
floatValue = val.doubleValue();
} else {
floatValue = Float.parseFloat(result);
}
if (!value.base().equals(0)) {
floatValue = Math.pow(value.base(), floatValue);
}
floatValue = floatValue * value.scale();
floatValue = floatValue + value.offset();
if (value.getType().toLowerCase().equals("f")
|| value.getType().toLowerCase().equals("float")) {
return String.valueOf(floatValue);
}
return String.valueOf(Math.round(floatValue));
}
示例11: transform
import java.math.BigInteger; //导入方法依赖的package包/类
public String transform(PropertyValue value, String result) {
double floatValue;
if (value.getLSB() != null) {
BigInteger val = parse(value, result);
if (!value.mask().equals(BigInteger.ZERO)) {
val = val.and(value.mask());
}
if (!value.shift().equals(0)) {
val = val.shiftRight(value.shift());
}
if (value.getSigned() && val.bitLength() == (value.size() * 4)) {
BigInteger complement =
new BigInteger(new String(new char[value.size()]).replace("\0", "F"), 16);
val = val.subtract(complement);
}
if (!objectCache.getTransformData()) {
int intValue = val.intValue();
return String.valueOf(intValue);
}
floatValue = val.doubleValue();
} else {
floatValue = Float.parseFloat(result);
}
if (!value.base().equals(0)) {
floatValue = Math.pow(value.base(), floatValue);
}
floatValue = floatValue * value.scale();
floatValue = floatValue + value.offset();
if (value.getType().toLowerCase().equals("f")
|| value.getType().toLowerCase().equals("float")) {
return String.valueOf(floatValue);
}
return String.valueOf(Math.round(floatValue));
}
示例12: abs
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Returns the Absolute value of integer.
*
* @param a number
* @return number which is always positive
*/
private static BigInteger abs(BigInteger a){
return (a.doubleValue()<=0) ? new BigInteger("0").subtract(a) : a;
}