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.codegen.CodeStream;
15 import org.eclipse.jdt.internal.compiler.impl.Constant;
16 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
17 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
18 import org.eclipse.jdt.internal.compiler.util.FloatUtil;
20 public class FloatLiteral extends NumberLiteral {
22 final static float Float_MIN_VALUE = Float.intBitsToFloat(1); // work-around VAJ problem 1F6IGUU
23 public FloatLiteral(char[] token, int s, int e) {
26 public void computeConstant() {
29 computedValue = Float.valueOf(String.valueOf(source));
30 } catch (NumberFormatException e) {
31 // hex floating point literal
32 // being rejected by 1.4 libraries where Float.valueOf(...) doesn't handle hex decimal floats
34 float v = FloatUtil.valueOfHexFloatLiteral(source);
35 if (v == Float.POSITIVE_INFINITY) {
36 // error: the number is too large to represent
40 // error: the number is too small to represent
44 constant = Constant.fromValue(v);
45 } catch (NumberFormatException e1) {
46 // if the computation of the constant fails
51 final float floatValue = computedValue.floatValue();
52 if (floatValue > Float.MAX_VALUE) {
53 // error: the number is too large to represent
56 if (floatValue < Float.MIN_VALUE) {
58 // a true 0 only has '0' and '.' in mantissa
59 // 1.0e-5000d is non-zero, but underflows to 0
60 boolean isHexaDecimal = false;
61 label : for (int i = 0; i < source.length; i++) { //it is welled formated so just test against '0' and potential . D d
79 // starting the exponent - mantissa is all zero
80 // no exponent - mantissa is all zero
86 // error: the number is too small to represent
92 constant = Constant.fromValue(value);
95 * Code generation for float literal
97 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
98 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
99 * @param valueRequired boolean
101 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
102 int pc = codeStream.position;
104 codeStream.generateConstant(constant, implicitConversion);
106 codeStream.recordPositionsFrom(pc, this.sourceStart);
108 public TypeBinding literalType(BlockScope scope) {
111 public void traverse(ASTVisitor visitor, BlockScope blockScope) {
112 visitor.visit(this, blockScope);
113 visitor.endVisit(this, blockScope);