本文整理汇总了Java中org.jscience.mathematics.number.LargeInteger类的典型用法代码示例。如果您正苦于以下问题:Java LargeInteger类的具体用法?Java LargeInteger怎么用?Java LargeInteger使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LargeInteger类属于org.jscience.mathematics.number包,在下文中一共展示了LargeInteger类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readRational
import org.jscience.mathematics.number.LargeInteger; //导入依赖的package包/类
private static Rational readRational(ByteBuf buf) {
int length = buf.readInt();
byte[] data = new byte[length];
buf.readBytes(data);
int divisorLength = buf.readInt();
LargeInteger divisor = LargeInteger.valueOf(data, 0, divisorLength);
LargeInteger dividend = LargeInteger.valueOf(data, divisorLength, length - divisorLength);
return Rational.valueOf(dividend, divisor);
}
示例2: writeRational
import org.jscience.mathematics.number.LargeInteger; //导入依赖的package包/类
private static void writeRational(ByteBuf buf, Rational r) {
LargeInteger divisor = r.getDivisor();
LargeInteger dividend = r.getDividend();
int byteLength = (divisor.bitLength() >> 3) + (dividend.bitLength() >> 3) + 2;
byte[] data = new byte[byteLength];
int written = divisor.toByteArray(data, 0);
int total = dividend.toByteArray(data, written);
buf.writeInt(total);
buf.writeInt(written);
buf.writeBytes(data, 0, total);
}
示例3: ratioToState
import org.jscience.mathematics.number.LargeInteger; //导入依赖的package包/类
private int ratioToState(Rational ratio) {
// bound at the edges
if (ratio.isGreaterThan(Rational.ONE)) {
return (int) (Q.maxState());
}
if (ratio.isLessThan(Rational.ONE.inverse())) {
return 0;
}
// it's a number in [-1, 1]
LargeInteger rq = ratio.getDividend().times(stepSize.getDividend());
Rational rqs = Rational.valueOf(rq, ratio.getDivisor());
int p = rqs.round().intValue();
return p + Q.middleState();
}