/*
* Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*/
package com.jfinal.template.io;
public class FloatingDecimal{
boolean isExceptional;
boolean isNegative;
int decExponent;
char digits[];
int nDigits;
int bigIntExp;
int bigIntNBits;
boolean mustSetRoundDir = false;
boolean fromHex = false;
int roundDir = 0; // set by doubleValue
/*
* Constants of the implementation
* Most are IEEE-754 related.
* (There are more really boring constants at the end.)
*/
static final long signMask = 0x8000000000000000L;
static final long expMask = 0x7ff0000000000000L;
static final long fractMask= ~(signMask|expMask);
static final int expShift = 52;
static final int expBias = 1023;
static final long fractHOB = ( 1L<<expShift ); // assumed High-Order bit
static final long expOne = ((long)expBias)<<expShift; // exponent of 1.0
static final int maxSmallBinExp = 62;
static final int minSmallBinExp = -( 63 / 3 );
static final int maxDecimalDigits = 15;
static final int maxDecimalExponent = 308;
static final int minDecimalExponent = -324;
static final int bigDecimalExponent = 324; // i.e. abs(minDecimalExponent)
static final long highbyte = 0xff00000000000000L;
static final long highbit = 0x8000000000000000L;
static final long lowbytes = ~highbyte;
static final int singleSignMask = 0x80000000;
static final int singleExpMask = 0x7f800000;
static final int singleFractMask = ~(singleSignMask|singleExpMask);
static final int singleExpShift = 23;
static final int singleFractHOB = 1<<singleExpShift;
static final int singleExpBias = 127;
static final int singleMaxDecimalDigits = 7;
static final int singleMaxDecimalExponent = 38;
static final int singleMinDecimalExponent = -45;
static final int intDecimalDigits = 9;
/*
* count number of bits from high-order 1 bit to low-order 1 bit,
* inclusive.
*/
private static int
countBits( long v ){
//
// the strategy is to shift until we get a non-zero sign bit
// then shift until we have no bits left, counting the difference.
// we do byte shifting as a hack. Hope it helps.
//
if ( v == 0L ) return 0;
while ( ( v & highbyte ) == 0L ){
v <<= 8;
}
while ( v > 0L ) { // i.e. while ((v&highbit) == 0L )
v <<= 1;
}
int n = 0;
while (( v & lowbytes ) != 0L ){
v <<= 8;
n += 8;
}
while ( v != 0L ){
v <<= 1;
n += 1;
}
return n;
}
/*
* Keep big powers of 5 handy for future reference.
*/
private static FDBigInt b5p[];
private static synchronized FDBigInt
big5pow( int p ){
assert p >= 0 : p; // negative power of 5
if ( b5p == null ){
b5p = new FDBigInt[ p+1 ];
}else if (b5p.length <= p ){
FDBigInt t[] = new FDBigInt[ p+1 ];
System.arraycopy( b5p, 0, t, 0, b5p.length );
b5p = t;
}
if ( b5p[p] != null )
return b5p[p];
else if ( p < small5pow.length )
return b5p[p] = new FDBigInt( small5pow[p] );
else if ( p < long5pow.length )
return b5p[p] = new FDBigInt( long5pow[p] );
else {
// construct the value.
// recursively.
int q, r;
// in order to compute 5^p,
// compute its square root, 5^(p/2) and square.
// or, let q = p / 2, r = p -q, then
// 5^p = 5^(q+r) = 5^q * 5^r
q = p >> 1;
r = p - q;
FDBigInt bigq = b5p[q];
if ( bigq == null )
bigq = big5pow ( q );
if ( r < small5pow.length ){
return (b5p[p] = bigq.mult( small5pow[r] ) );
}else{
FDBigInt bigr = b5p[ r ];
if ( bigr == null )
bigr = big5pow( r );
return (b5p[p] = bigq.mult( bigr ) );
}
}
}
//
// a common operation
//
private static FDBigInt
multPow52( FDBigInt v, int p5, int p2 ){
if ( p5 != 0 ){
if ( p5 < small5pow.length ){
v = v.mult( small5pow[p5] );
} else {
v = v.mult( big5pow( p5 ) );
}
}
if ( p2 != 0 ){
v.lshiftMe( p2 );
}
return v;
}
//
// another common operation
//
private static FDBigInt
constructPow52( int p5, int p2 ){
FDBigInt v = new FDBigInt( big5pow( p5 ) );
if ( p2 != 0 ){
v.lshiftMe( p2 );
}
return v;
}
/*
* This is the easy subcase --
* all the significant bits, after scaling, are held in lvalue.
* negSign and decExponent tell us what processing and scaling
* has already been done. Exceptional cases have already been
* stripped out.
* In particular:
* lvalue is a finite number (not Inf, nor NaN)
* lvalue > 0L (not zero, nor negative).
*
* The only reason that we develop the digits here, rather than
* calling on Long.toString() is that we can do it a little faster,
* and besides want to treat trailing 0s specially. If Long.toString
* changes, we should re-evaluate this strategy!
*/
private void
developLongDigits( int decExponent, long lvalue, long insignificant ){
char digits[];
int ndigits;
int digitno;
int c;
//
// Discard non-significant low-order bits, while rounding,
// up to insignificant value.
int i;
for ( i = 0; insignificant >= 10L; i++ )
insignificant /= 10L;
if ( i != 0 ){
long pow10 = long5pow[i] << i; // 10^i == 5^i * 2^i;
long residue = lvalue % pow10;
lvalue /= pow10;
decExponent += i;
if ( residue >= (pow10>>1) ){
// round up based on the low-order bits we're discarding
lvalue++;
}
}
if ( lvalue <= Integer.MAX_VALUE ){
assert lvalue > 0L : lvalue; // lvalue <= 0
// even easier subcase!
// can do int arithmetic rather than long!
int ivalue = (int)lvalue;
ndigits = 10;
digits = (char[])(perThreadBuffer.get());
digitno = ndigits-1;
c = ivalue%10;
ivalue /= 10;
while ( c == 0 ){
decExponent++;
c = ivalue%10;
ivalue /= 10;
}
while ( ivalue != 0){
digits[digitno--] = (char)(c+'0');
decExponent++;
c = ivalue%10;
ivalue /= 10;
}
digits[digitno] = (char)(c+'0');
} else {
// same algorithm as above (same bugs, too )
// but using long arithmetic.
ndigits = 20;
digits = (char[])(perThreadBuffer.get());
digitno = ndigits-1;
c = (int)(lvalue%10L);
lvalue /= 10L;
while ( c == 0 ){
decExponent++;
c = (int)(lvalue%10L);
lvalue /= 10L;
}
while ( lvalue != 0L ){
digits[digitno--] = (char)(c+'0');
decExponent++;
c = (int)(lvalue%10L);
lvalue /= 10;
}
digits[digitno] = (char)(c+'0');
}
char result [];
ndigits -= digitno;
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Enjoy 是基于 Java 语言的极轻量极魔板引擎。极轻量级仅 228 KB 并且不依赖任何第三方。极简设计仅 if、for、switch、set、define、include、render 七个核心指令,让学习成本低到极致。独创 DKFF(Dynamic Key Feature Forward) 词法分析算法与 DLRD (Double Layer Recursive Descent)语法分析算法,避免使用 javacc、antlr、jflex 生成器,令代码量少到极致。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java语言的极轻量极魔板引擎 极轻量级仅228KB 并且不依赖任何第三方 极简设计仅七个核心指令,让学习成本低到极致 (148个子文件)
.gitignore 444B
FloatingDecimal.java 45KB
Engine.java 22KB
Lexer.java 16KB
EngineConfig.java 15KB
MethodKit.java 14KB
ExprParser.java 13KB
ExprLexer.java 12KB
Compare.java 10KB
Arith.java 10KB
JFinalViewResolver.java 9KB
Parser.java 8KB
TimeKit.java 8KB
FieldGetters.java 7KB
Template.java 7KB
PropKit.java 7KB
ProxyCompiler.java 7KB
RenderDirective.java 7KB
Prop.java 7KB
TypeKit.java 6KB
Scope.java 6KB
SharedMethodKit.java 6KB
Include.java 6KB
FastFieldGetter.java 6KB
StrKit.java 5KB
ForIteratorStatus.java 5KB
ClassPathSource.java 5KB
FieldKit.java 5KB
Method.java 5KB
JFinalView.java 5KB
LineCompressor.java 5KB
IntegerWriter.java 4KB
Define.java 4KB
Okv.java 4KB
Assign.java 4KB
Unary.java 4KB
MethodKeyBuilder.java 4KB
FastStringWriter.java 4KB
Kv.java 4KB
FieldKeyBuilder.java 4KB
IncDec.java 4KB
NumTok.java 4KB
SyncWriteMap.java 4KB
For.java 4KB
Utf8Encoder.java 4KB
CharTable.java 4KB
Env.java 4KB
Field.java 3KB
NumberDirective.java 3KB
Switch.java 3KB
DateDirective.java 3KB
HashKit.java 3KB
Text.java 3KB
MethodInfo.java 3KB
StringExt.java 3KB
TextToken.java 3KB
FileSource.java 3KB
WriterBuffer.java 3KB
ExprList.java 3KB
CallDirective.java 3KB
StaticMethod.java 3KB
ByteWriter.java 3KB
Compressor.java 3KB
LongWriter.java 3KB
StringDirective.java 3KB
Logic.java 3KB
Ctrl.java 3KB
CharWriter.java 3KB
Symbol.java 3KB
RangeArray.java 3KB
Index.java 3KB
Case.java 2KB
Const.java 2KB
StringSource.java 2KB
IntegerExt.java 2KB
EscapeDirective.java 2KB
SharedMethod.java 2KB
Map.java 2KB
StatList.java 2KB
Output.java 2KB
SharedMethodLib.java 2KB
ForCtrl.java 2KB
ProxyClass.java 2KB
Writer.java 2KB
NowDirective.java 2KB
JavaKeyword.java 2KB
NullSafe.java 2KB
ElKit.java 2KB
FloatingWriter.java 2KB
BigDecimalExt.java 2KB
SetLocal.java 2KB
SetGlobal.java 2KB
ReflectKit.java 2KB
Directive.java 2KB
Set.java 2KB
ProxyClassLoader.java 2KB
FieldGetter.java 2KB
JdkEncoder.java 2KB
MethodInfoExt.java 2KB
OutputDirectiveFactory.java 2KB
共 148 条
- 1
- 2
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 7529
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- chromedriver-linux64_122.0.6168.0.zip
- chromedriver-linux64_122.0.6170.0.zip
- chromedriver-linux64_122.0.6171.0.zip
- chromedriver-linux64_122.0.6170.3.zip
- chromedriver-linux64_122.0.6170.5.zip
- chromedriver-linux64_122.0.6172.0.zip
- chromedriver-linux64_122.0.6174.0.zip
- chromedriver-linux64_122.0.6173.0.zip
- chromedriver-linux64_122.0.6178.0.zip
- chromedriver-linux64_122.0.6177.0.zip
- chromedriver-linux64_122.0.6176.0.zip
- chromedriver-linux64_122.0.6179.0.zip
- chromedriver-linux64_122.0.6179.2.zip
- chromedriver-linux64_122.0.6180.0.zip
- chromedriver-linux64_122.0.6183.0.zip
- chromedriver-linux64_122.0.6182.0.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功