1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.compiler.ast;
13 import org.eclipse.jdt.internal.compiler.ASTVisitor;
14 import org.eclipse.jdt.internal.compiler.impl.*;
15 import org.eclipse.jdt.internal.compiler.codegen.*;
16 import org.eclipse.jdt.internal.compiler.lookup.*;
17 import org.eclipse.jdt.internal.compiler.util.FloatUtil;
19 public class DoubleLiteral extends NumberLiteral {
21 public DoubleLiteral(char[] token, int s, int e) {
24 public void computeConstant() {
27 computedValue = Double.valueOf(String.valueOf(source));
28 } catch (NumberFormatException e) {
29 // hex floating point literal
30 // being rejected by 1.4 libraries where Double.valueOf(...) doesn't handle hex decimal floats
32 double v = FloatUtil.valueOfHexDoubleLiteral(source);
33 if (v == Double.POSITIVE_INFINITY) {
34 // error: the number is too large to represent
37 if (Double.isNaN(v)) {
38 // error: the number is too small to represent
42 constant = Constant.fromValue(v);
43 } catch (NumberFormatException e1) {
44 // if the computation of the constant fails
49 final double doubleValue = computedValue.doubleValue();
50 if (doubleValue > Double.MAX_VALUE) {
51 // error: the number is too large to represent
54 if (doubleValue < Double.MIN_VALUE) {
56 // a true 0 only has '0' and '.' in mantissa
57 // 1.0e-5000d is non-zero, but underflows to 0
58 boolean isHexaDecimal = false;
59 label : for (int i = 0; i < source.length; i++) { //it is welled formated so just test against '0' and potential . D d
77 // starting the exponent - mantissa is all zero
78 // no exponent - mantissa is all zero
84 // error: the number is too small to represent
90 constant = Constant.fromValue(value);
93 * Code generation for the double literak
95 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
96 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
97 * @param valueRequired boolean
99 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
100 int pc = codeStream.position;
102 codeStream.generateConstant(constant, implicitConversion);
104 codeStream.recordPositionsFrom(pc, this.sourceStart);
106 public TypeBinding literalType(BlockScope scope) {
107 return DoubleBinding;
109 public void traverse(ASTVisitor visitor, BlockScope blockScope) {
110 visitor.visit(this, blockScope);
111 visitor.endVisit(this, blockScope);