1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.dexgen.rop.cst; 18 19 import com.android.dexgen.rop.type.Type; 20 import com.android.dexgen.util.Hex; 21 22 /** 23 * Constants of type {@code CONSTANT_Double_info}. 24 */ 25 public final class CstDouble 26 extends CstLiteral64 { 27 /** {@code non-null;} instance representing {@code 0} */ 28 public static final CstDouble VALUE_0 = 29 new CstDouble(Double.doubleToLongBits(0.0)); 30 31 /** {@code non-null;} instance representing {@code 1} */ 32 public static final CstDouble VALUE_1 = 33 new CstDouble(Double.doubleToLongBits(1.0)); 34 35 /** 36 * Makes an instance for the given value. This may (but does not 37 * necessarily) return an already-allocated instance. 38 * 39 * @param bits the {@code double} value as {@code long} bits 40 */ make(long bits)41 public static CstDouble make(long bits) { 42 /* 43 * Note: Javadoc notwithstanding, this implementation always 44 * allocates. 45 */ 46 return new CstDouble(bits); 47 } 48 49 /** 50 * Constructs an instance. This constructor is private; use {@link #make}. 51 * 52 * @param bits the {@code double} value as {@code long} bits 53 */ CstDouble(long bits)54 private CstDouble(long bits) { 55 super(bits); 56 } 57 58 /** {@inheritDoc} */ 59 @Override toString()60 public String toString() { 61 long bits = getLongBits(); 62 return "double{0x" + Hex.u8(bits) + " / " + 63 Double.longBitsToDouble(bits) + '}'; 64 } 65 66 /** {@inheritDoc} */ getType()67 public Type getType() { 68 return Type.DOUBLE; 69 } 70 71 /** {@inheritDoc} */ 72 @Override typeName()73 public String typeName() { 74 return "double"; 75 } 76 77 /** {@inheritDoc} */ toHuman()78 public String toHuman() { 79 return Double.toString(Double.longBitsToDouble(getLongBits())); 80 } 81 82 /** 83 * Gets the {@code double} value. 84 * 85 * @return the value 86 */ getValue()87 public double getValue() { 88 return Double.longBitsToDouble(getLongBits()); 89 } 90 } 91