< prev index next >

src/java.base/share/classes/jdk/internal/math/FormattedFloatingDecimal.java

Print this page

 33 
 34 
 35     public static FormattedFloatingDecimal valueOf(double d, int precision, Form form){
 36         FloatingDecimal.BinaryToASCIIConverter fdConverter =
 37                 FloatingDecimal.getBinaryToASCIIConverter(d, form == Form.COMPATIBLE);
 38         return new FormattedFloatingDecimal(precision,form, fdConverter);
 39     }
 40 
 41     private int decExponentRounded;
 42     private char[] mantissa;
 43     private char[] exponent;
 44 
 45     private static final ThreadLocal<Object> threadLocalCharBuffer =
 46             new ThreadLocal<Object>() {
 47                 @Override
 48                 protected Object initialValue() {
 49                     return new char[20];
 50                 }
 51             };
 52 
 53     private static char[] getBuffer(){
 54         return (char[]) threadLocalCharBuffer.get();




 55     }
 56 
 57     private FormattedFloatingDecimal(int precision, Form form, FloatingDecimal.BinaryToASCIIConverter fdConverter) {
 58         if (fdConverter.isExceptional()) {
 59             this.mantissa = fdConverter.toJavaFormatString().toCharArray();
 60             this.exponent = null;
 61             return;
 62         }
 63         char[] digits = getBuffer();
 64         int nDigits = fdConverter.getDigits(digits);
 65         int decExp = fdConverter.getDecimalExponent();
 66         int exp;
 67         boolean isNegative = fdConverter.isNegative();
 68         switch (form) {
 69             case COMPATIBLE:
 70                 exp = decExp;
 71                 this.decExponentRounded = exp;
 72                 fillCompatible(precision, digits, nDigits, exp, isNegative);
 73                 break;
 74             case DECIMAL_FLOAT:

 33 
 34 
 35     public static FormattedFloatingDecimal valueOf(double d, int precision, Form form){
 36         FloatingDecimal.BinaryToASCIIConverter fdConverter =
 37                 FloatingDecimal.getBinaryToASCIIConverter(d, form == Form.COMPATIBLE);
 38         return new FormattedFloatingDecimal(precision,form, fdConverter);
 39     }
 40 
 41     private int decExponentRounded;
 42     private char[] mantissa;
 43     private char[] exponent;
 44 
 45     private static final ThreadLocal<Object> threadLocalCharBuffer =
 46             new ThreadLocal<Object>() {
 47                 @Override
 48                 protected Object initialValue() {
 49                     return new char[20];
 50                 }
 51             };
 52 
 53     private static char[] getBuffer() {
 54         if (Thread.currentThread().isVirtual()) {
 55             return new char[20];
 56         } else {
 57             return (char[]) threadLocalCharBuffer.get();
 58         }
 59     }
 60 
 61     private FormattedFloatingDecimal(int precision, Form form, FloatingDecimal.BinaryToASCIIConverter fdConverter) {
 62         if (fdConverter.isExceptional()) {
 63             this.mantissa = fdConverter.toJavaFormatString().toCharArray();
 64             this.exponent = null;
 65             return;
 66         }
 67         char[] digits = getBuffer();
 68         int nDigits = fdConverter.getDigits(digits);
 69         int decExp = fdConverter.getDecimalExponent();
 70         int exp;
 71         boolean isNegative = fdConverter.isNegative();
 72         switch (form) {
 73             case COMPATIBLE:
 74                 exp = decExp;
 75                 this.decExponentRounded = exp;
 76                 fillCompatible(precision, digits, nDigits, exp, isNegative);
 77                 break;
 78             case DECIMAL_FLOAT:
< prev index next >