GP-1379/3022 revert rename of float types back to byte-size for future

consideration
This commit is contained in:
ghidra1 2023-04-26 18:39:18 -04:00
parent 6d85c6cbc1
commit e2003f4c1b
31 changed files with 115 additions and 198 deletions

View File

@ -27,7 +27,6 @@ import ghidra.dbg.target.TargetDataTypeMember;
import ghidra.dbg.target.TargetNamedDataType;
import ghidra.dbg.util.PathUtils.TargetObjectKeyComparator;
import ghidra.program.model.data.*;
import ghidra.program.model.data.floats.AbstractFloatDataType;
import ghidra.util.Msg;
public class TargetDataTypeConverter {

View File

@ -23,8 +23,8 @@ import db.DBRecord;
import ghidra.program.database.data.DataTypeUtilities;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.data.AbstractFloatDataType;
import ghidra.program.model.data.DataType;
import ghidra.program.model.data.floats.AbstractFloatDataType;
import ghidra.program.model.lang.Register;
import ghidra.program.model.listing.*;
import ghidra.program.model.pcode.Varnode;

View File

@ -22,7 +22,6 @@ import ghidra.app.util.cparser.C.ParseException;
import ghidra.app.util.parser.FunctionSignatureParser;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.*;
import ghidra.program.model.data.floats.AbstractFloatDataType;
import ghidra.program.model.lang.*;
import ghidra.program.model.listing.*;
import ghidra.program.model.listing.Function.FunctionUpdateType;

View File

@ -33,7 +33,6 @@ import ghidra.app.util.datatype.DataTypeSelectionEditor;
import ghidra.app.util.datatype.NavigationDirection;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.*;
import ghidra.program.model.data.floats.AbstractFloatDataType;
import ghidra.program.model.lang.Register;
import ghidra.program.model.listing.*;
import ghidra.util.HelpLocation;

View File

@ -25,7 +25,6 @@ import ghidra.app.util.bin.format.dwarf4.encoding.*;
import ghidra.app.util.bin.format.dwarf4.expression.DWARFExpressionException;
import ghidra.app.util.bin.format.dwarf4.next.DWARFDataTypeImporter.DWARFDataType;
import ghidra.program.model.data.*;
import ghidra.program.model.data.floats.AbstractFloatDataType;
import ghidra.program.model.lang.CompilerSpec;
import ghidra.program.model.listing.Program;
import ghidra.util.Msg;

View File

@ -25,8 +25,6 @@ import ghidra.app.util.bin.format.pe.cli.streams.CliStreamMetadata;
import ghidra.app.util.bin.format.pe.cli.tables.*;
import ghidra.app.util.bin.format.pe.cli.tables.indexes.CliIndexTypeDefOrRef;
import ghidra.program.model.data.*;
import ghidra.program.model.data.floats.Float32DataType;
import ghidra.program.model.data.floats.Float64DataType;
import ghidra.util.exception.InvalidInputException;
public abstract class CliAbstractSig extends CliBlob implements CliRepresentable {
@ -141,9 +139,9 @@ public abstract class CliAbstractSig extends CliBlob implements CliRepresentable
return UnsignedIntegerDataType.dataType;
case ELEMENT_TYPE_R4:
return Float32DataType.dataType;
return Float4DataType.dataType;
case ELEMENT_TYPE_R8:
return Float64DataType.dataType;
return Float8DataType.dataType;
case ELEMENT_TYPE_I8:
return LongLongDataType.dataType;

View File

@ -32,8 +32,6 @@ import ghidra.app.util.bin.format.pe.cli.tables.CliTableMethodDef.CliMethodDefRo
import ghidra.app.util.bin.format.pe.cli.tables.CliTypeTable;
import ghidra.app.util.bin.format.pe.cli.tables.indexes.CliIndexCustomAttributeType;
import ghidra.program.model.data.*;
import ghidra.program.model.data.floats.Float32DataType;
import ghidra.program.model.data.floats.Float64DataType;
import ghidra.util.Msg;
import ghidra.util.exception.InvalidInputException;
@ -412,12 +410,12 @@ public class CliBlobCustomAttrib extends CliBlob {
case ELEMENT_TYPE_R4:
addFixedArg(processFixedArgs, baseTypeCode,
reader.readNextByteArray(Float32DataType.dataType.getLength()));
reader.readNextByteArray(Float4DataType.dataType.getLength()));
break;
case ELEMENT_TYPE_R8:
addFixedArg(processFixedArgs, baseTypeCode,
reader.readNextByteArray(Float64DataType.dataType.getLength()));
reader.readNextByteArray(Float8DataType.dataType.getLength()));
break;
case ELEMENT_TYPE_STRING:

View File

@ -25,7 +25,6 @@ import org.apache.commons.lang3.StringUtils;
import ghidra.program.database.data.DataTypeUtilities;
import ghidra.program.model.data.*;
import ghidra.program.model.data.Enum;
import ghidra.program.model.data.floats.Float128DataType;
import ghidra.program.model.symbol.Namespace;
/**
@ -284,7 +283,7 @@ public class DemangledDataType extends DemangledType {
dt = FloatDataType.dataType;
}
else if (FLOAT128.equals(name)) {
dt = new TypedefDataType(FLOAT128, Float128DataType.dataType);
dt = new TypedefDataType(FLOAT128, Float16DataType.dataType);
}
else if (DOUBLE.equals(name)) {
dt = DoubleDataType.dataType;

View File

@ -20,7 +20,6 @@ import java.util.*;
import ghidra.app.util.bin.format.pdb2.pdbreader.PdbLog;
import ghidra.app.util.bin.format.pdb2.pdbreader.type.PrimitiveMsType;
import ghidra.program.model.data.*;
import ghidra.program.model.data.floats.AbstractFloatDataType;
import ghidra.util.exception.AssertException;
/**

View File

@ -23,7 +23,6 @@ import ghidra.app.util.SymbolPathParser;
import ghidra.docking.settings.Settings;
import ghidra.program.model.data.*;
import ghidra.program.model.data.Enum;
import ghidra.program.model.data.floats.AbstractFloatDataType;
import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.Namespace;
import ghidra.util.UniversalID;

View File

@ -19,7 +19,6 @@ import java.math.BigDecimal;
import generic.complex.Complex;
import ghidra.docking.settings.Settings;
import ghidra.program.model.data.floats.AbstractFloatDataType;
import ghidra.program.model.mem.MemBuffer;
import ghidra.program.model.mem.WrappedMemBuffer;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.program.model.data.floats;
package ghidra.program.model.data;
import java.math.BigInteger;
import java.util.TreeMap;
@ -22,7 +22,6 @@ import ghidra.docking.settings.Settings;
import ghidra.docking.settings.SettingsDefinition;
import ghidra.pcode.floatformat.*;
import ghidra.pcode.utils.Utils;
import ghidra.program.model.data.*;
import ghidra.program.model.mem.MemBuffer;
/**
@ -224,11 +223,11 @@ public abstract class AbstractFloatDataType extends BuiltIn {
if (floatTypes == null) {
// unsupported sizes filled-in with a null
floatTypes = new TreeMap<Integer, AbstractFloatDataType>();
floatTypes.put(Float2DataType.dataType.getLength(), Float2DataType.dataType);
floatTypes.put(Float4DataType.dataType.getLength(), Float4DataType.dataType);
floatTypes.put(Float8DataType.dataType.getLength(), Float8DataType.dataType);
floatTypes.put(Float10DataType.dataType.getLength(), Float10DataType.dataType);
floatTypes.put(Float16DataType.dataType.getLength(), Float16DataType.dataType);
floatTypes.put(Float32DataType.dataType.getLength(), Float32DataType.dataType);
floatTypes.put(Float64DataType.dataType.getLength(), Float64DataType.dataType);
floatTypes.put(Float80DataType.dataType.getLength(), Float80DataType.dataType);
floatTypes.put(Float128DataType.dataType.getLength(), Float128DataType.dataType);
}
return floatTypes;
}

View File

@ -15,8 +15,6 @@
*/
package ghidra.program.model.data;
import ghidra.program.model.data.floats.Float64DataType;
/**
* Provides a definition of a {@code complex} built-in data type consisting of two 64-bit floating point
* numbers in the IEEE 754 double precision format.
@ -30,7 +28,7 @@ public class Complex16DataType extends AbstractComplexDataType {
}
public Complex16DataType(DataTypeManager dtm) {
super("complex16", Float64DataType.dataType, dtm);
super("complex16", Float8DataType.dataType, dtm);
}
@Override

View File

@ -15,8 +15,6 @@
*/
package ghidra.program.model.data;
import ghidra.program.model.data.floats.Float128DataType;
/**
* Provides a definition of a {@code complex} built-in data type consisting of two 128-bit floating point
* numbers in the IEEE 754 double precision format.
@ -30,7 +28,7 @@ public class Complex32DataType extends AbstractComplexDataType {
}
public Complex32DataType(DataTypeManager dtm) {
super("complex32", Float128DataType.dataType, dtm);
super("complex32", Float16DataType.dataType, dtm);
}
@Override

View File

@ -15,8 +15,6 @@
*/
package ghidra.program.model.data;
import ghidra.program.model.data.floats.Float32DataType;
/**
* Provides a definition of a {@code complex} built-in data type consisting of two 32-bit floating point
* numbers in the IEEE 754 double precision format.
@ -31,7 +29,7 @@ public class Complex8DataType extends AbstractComplexDataType {
}
public Complex8DataType(DataTypeManager dtm) {
super("complex8", Float32DataType.dataType, dtm);
super("complex8", Float4DataType.dataType, dtm);
}
@Override

View File

@ -15,8 +15,6 @@
*/
package ghidra.program.model.data;
import ghidra.program.model.data.floats.AbstractFloatDataType;
/**
* Provides a definition of a Double within a program.
*/

View File

@ -13,28 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.program.model.data.floats;
package ghidra.program.model.data;
import ghidra.program.model.data.DataType;
import ghidra.program.model.data.DataTypeManager;
import ghidra.util.classfinder.ClassTranslator;
public class Float10DataType extends AbstractFloatDataType {
public class Float64DataType extends AbstractFloatDataType {
public static final Float10DataType dataType = new Float10DataType();
static {
// remap old byte-sized float to this bit-sized equivalent
ClassTranslator.put(
"ghidra.program.model.data.Float8DataType", Float64DataType.class.getName());
}
public static final Float64DataType dataType = new Float64DataType();
public Float64DataType() {
public Float10DataType() {
this(null);
}
public Float64DataType(DataTypeManager dtm) {
super("float64", 8, dtm);
public Float10DataType(DataTypeManager dtm) {
super("float10", 10, dtm);
}
@Override
@ -42,7 +32,7 @@ public class Float64DataType extends AbstractFloatDataType {
if (dtm == getDataTypeManager()) {
return this;
}
return new Float64DataType(dtm);
return new Float10DataType(dtm);
}
}

View File

@ -13,20 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.program.model.data.floats;
import ghidra.program.model.data.DataType;
import ghidra.program.model.data.DataTypeManager;
import ghidra.util.classfinder.ClassTranslator;
package ghidra.program.model.data;
public class Float16DataType extends AbstractFloatDataType {
static {
// remap old byte-sized float to this bit-sized equivalent
ClassTranslator.put(
"ghidra.program.model.data.Float2DataType", Float16DataType.class.getName());
}
public static final Float16DataType dataType = new Float16DataType();
public Float16DataType() {
@ -34,7 +24,7 @@ public class Float16DataType extends AbstractFloatDataType {
}
public Float16DataType(DataTypeManager dtm) {
super("float16", 2, dtm);
super("float16", 16, dtm);
}
@Override

View File

@ -13,28 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.program.model.data.floats;
package ghidra.program.model.data;
import ghidra.program.model.data.DataType;
import ghidra.program.model.data.DataTypeManager;
import ghidra.util.classfinder.ClassTranslator;
public class Float2DataType extends AbstractFloatDataType {
public class Float32DataType extends AbstractFloatDataType {
public static final Float2DataType dataType = new Float2DataType();
static {
// remap old byte-sized float to this bit-sized equivalent
ClassTranslator.put(
"ghidra.program.model.data.Float4DataType", Float32DataType.class.getName());
}
public static final Float32DataType dataType = new Float32DataType();
public Float32DataType() {
public Float2DataType() {
this(null);
}
public Float32DataType(DataTypeManager dtm) {
super("float32", 4, dtm);
public Float2DataType(DataTypeManager dtm) {
super("float2", 2, dtm);
}
@Override
@ -42,7 +32,7 @@ public class Float32DataType extends AbstractFloatDataType {
if (dtm == getDataTypeManager()) {
return this;
}
return new Float32DataType(dtm);
return new Float2DataType(dtm);
}
}

View File

@ -13,28 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.program.model.data.floats;
package ghidra.program.model.data;
import ghidra.program.model.data.DataType;
import ghidra.program.model.data.DataTypeManager;
import ghidra.util.classfinder.ClassTranslator;
public class Float4DataType extends AbstractFloatDataType {
public class Float80DataType extends AbstractFloatDataType {
public static final Float4DataType dataType = new Float4DataType();
static {
// remap old byte-sized float to this bit-sized equivalent
ClassTranslator.put(
"ghidra.program.model.data.Float10DataType", Float80DataType.class.getName());
}
public static final Float80DataType dataType = new Float80DataType();
public Float80DataType() {
public Float4DataType() {
this(null);
}
public Float80DataType(DataTypeManager dtm) {
super("float80", 10, dtm);
public Float4DataType(DataTypeManager dtm) {
super("float4", 4, dtm);
}
@Override
@ -42,7 +32,7 @@ public class Float80DataType extends AbstractFloatDataType {
if (dtm == getDataTypeManager()) {
return this;
}
return new Float80DataType(dtm);
return new Float4DataType(dtm);
}
}

View File

@ -0,0 +1,38 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.program.model.data;
public class Float8DataType extends AbstractFloatDataType {
public static final Float8DataType dataType = new Float8DataType();
public Float8DataType() {
this(null);
}
public Float8DataType(DataTypeManager dtm) {
super("float8", 8, dtm);
}
@Override
public DataType clone(DataTypeManager dtm) {
if (dtm == getDataTypeManager()) {
return this;
}
return new Float8DataType(dtm);
}
}

View File

@ -15,8 +15,6 @@
*/
package ghidra.program.model.data;
import ghidra.program.model.data.floats.AbstractFloatDataType;
/**
* Provides a definition of a Float within a program.
*/

View File

@ -15,8 +15,6 @@
*/
package ghidra.program.model.data;
import ghidra.program.model.data.floats.AbstractFloatDataType;
/**
* Provides a definition of a Long Double within a program.
*/

View File

@ -15,8 +15,6 @@
*/
package ghidra.program.model.data;
import ghidra.program.model.data.floats.AbstractFloatDataType;
public enum MetaDataType {
// Enumerations are ordered in terms of how "specific" the data-type class is
VOID, // "void" data-type

View File

@ -1,48 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.program.model.data.floats;
import ghidra.program.model.data.DataType;
import ghidra.program.model.data.DataTypeManager;
import ghidra.util.classfinder.ClassTranslator;
public class Float128DataType extends AbstractFloatDataType {
static {
// remap old byte-sized float to this bit-sized equivalent
ClassTranslator.put(
"ghidra.program.model.data.Float16DataType", Float128DataType.class.getName());
}
public static final Float128DataType dataType = new Float128DataType();
public Float128DataType() {
this(null);
}
public Float128DataType(DataTypeManager dtm) {
super("float128", 16, dtm);
}
@Override
public DataType clone(DataTypeManager dtm) {
if (dtm == getDataTypeManager()) {
return this;
}
return new Float128DataType(dtm);
}
}

View File

@ -26,7 +26,6 @@ import ghidra.app.plugin.processors.sleigh.VarnodeData;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.data.*;
import ghidra.program.model.data.floats.AbstractFloatDataType;
import ghidra.program.model.pcode.*;
import ghidra.util.SystemUtilities;
import ghidra.util.xml.SpecXmlUtils;

View File

@ -20,7 +20,6 @@ import java.util.*;
import ghidra.program.database.data.DataTypeUtilities;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.*;
import ghidra.program.model.data.floats.AbstractFloatDataType;
import ghidra.program.model.lang.*;
import ghidra.program.model.pcode.Varnode;
import ghidra.program.model.symbol.Namespace;

View File

@ -18,7 +18,7 @@ package ghidra.program.model.pcode;
import java.io.IOException;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.floats.AbstractFloatDataType;
import ghidra.program.model.data.AbstractFloatDataType;
import ghidra.program.model.listing.Program;
import ghidra.program.model.listing.VariableStorage;
import ghidra.program.model.mem.MemoryBlock;

View File

@ -28,7 +28,6 @@ import ghidra.program.database.data.PointerTypedefInspector;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.data.*;
import ghidra.program.model.data.Enum;
import ghidra.program.model.data.floats.AbstractFloatDataType;
import ghidra.program.model.lang.CompilerSpec;
import ghidra.program.model.lang.DecompilerLanguage;
import ghidra.program.model.listing.Program;

View File

@ -21,8 +21,6 @@ import org.junit.Test;
import generic.test.AbstractGTest;
import ghidra.pcode.floatformat.*;
import ghidra.program.model.data.floats.Float32DataType;
import ghidra.program.model.data.floats.Float64DataType;
import ghidra.program.model.mem.ByteMemBufferImpl;
import ghidra.util.LittleEndianDataConverter;
@ -42,49 +40,49 @@ public class FloatDataTypeTest extends AbstractGTest {
int bits = Float.floatToRawIntBits(Float.NaN);
byte[] bytes = getBytes(bits, 4);
Object value =
Float32DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
Float4DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
assertEquals(ff.getBigNaN(false), value);
bits = Float.floatToRawIntBits(Float.POSITIVE_INFINITY);
bytes = getBytes(bits, 4);
value =
Float32DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
Float4DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
assertEquals(ff.getBigInfinity(false), value);
bits = Float.floatToRawIntBits(Float.NEGATIVE_INFINITY);
bytes = getBytes(bits, 4);
value =
Float32DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
Float4DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
assertEquals(ff.getBigInfinity(true), value);
bits = Float.floatToRawIntBits(0F);
bytes = getBytes(bits, 4);
value =
Float32DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
Float4DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
assertEquals("0.0", ff.toDecimalString((BigFloat) value));
bits = Float.floatToRawIntBits(1F);
bytes = getBytes(bits, 4);
value =
Float32DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
Float4DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
assertEquals("1.0", ff.toDecimalString((BigFloat) value));
bits = Float.floatToRawIntBits(-1F);
bytes = getBytes(bits, 4);
value =
Float32DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
Float4DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
assertEquals("-1.0", ff.toDecimalString((BigFloat) value));
bits = Float.floatToRawIntBits(555.555F);
bytes = getBytes(bits, 4);
value =
Float32DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
Float4DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
assertEquals("555.55499", ff.toDecimalString((BigFloat) value, true));
bits = Float.floatToRawIntBits(-555.555F);
bytes = getBytes(bits, 4);
value =
Float32DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
Float4DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
assertEquals("-555.55499", ff.toDecimalString((BigFloat) value, true));
}
@ -97,49 +95,49 @@ public class FloatDataTypeTest extends AbstractGTest {
long bits = Double.doubleToRawLongBits(Double.NaN);
byte[] bytes = getBytes(bits, 8);
Object value =
Float64DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
Float8DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
assertEquals(ff.getBigNaN(false), value);
bits = Double.doubleToRawLongBits(Double.POSITIVE_INFINITY);
bytes = getBytes(bits, 8);
value =
Float64DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
Float8DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
assertEquals(ff.getBigInfinity(false), value);
bits = Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY);
bytes = getBytes(bits, 8);
value =
Float64DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
Float8DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
assertEquals(ff.getBigInfinity(true), value);
bits = Double.doubleToRawLongBits(0D);
bytes = getBytes(bits, 8);
value =
Float64DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
Float8DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
assertEquals("0.0", ff.toDecimalString((BigFloat) value));
bits = Double.doubleToRawLongBits(1D);
bytes = getBytes(bits, 8);
value =
Float64DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
Float8DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
assertEquals("1.0", ff.toDecimalString((BigFloat) value));
bits = Double.doubleToRawLongBits(-1D);
bytes = getBytes(bits, 8);
value =
Float64DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
Float8DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
assertEquals("-1.0", ff.toDecimalString((BigFloat) value));
bits = Double.doubleToRawLongBits(555.555D);
bytes = getBytes(bits, 8);
value =
Float64DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
Float8DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
assertEquals("555.5549999999999", ff.toDecimalString((BigFloat) value, true));
bits = Double.doubleToRawLongBits(-555.555D);
bytes = getBytes(bits, 8);
value =
Float64DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
Float8DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, false), null, 10);
assertEquals("-555.5549999999999", ff.toDecimalString((BigFloat) value, true));
}

View File

@ -23,11 +23,10 @@ import org.junit.Test;
import generic.test.AbstractGTest;
import ghidra.pcode.floatformat.*;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.floats.Float80DataType;
import ghidra.program.model.mem.ByteMemBufferImpl;
import ghidra.program.model.mem.MemBuffer;
public class Float80DataTypeTest extends AbstractGTest {
public class Float10DataTypeTest extends AbstractGTest {
@Test
public void testGetValue() {
@ -36,19 +35,19 @@ public class Float80DataTypeTest extends AbstractGTest {
byte[] bytes = bytes(0x7f, 0xff, 0, 0, 0, 0, 0, 0, 0, 0); // 0x7fff0000000000000000 = +infinity
BigFloat value =
Float80DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Float10DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Assert.assertEquals(ff.getBigInfinity(false), value);
Assert.assertEquals("+Infinity", ff.toDecimalString(value, true));
bytes = bytes(0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0); // 0xffff0000000000000000 = -infinity
value =
Float80DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Float10DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Assert.assertEquals(ff.getBigInfinity(true), value);
Assert.assertEquals("-Infinity", ff.toDecimalString(value, true));
bytes = bytes(0x7f, 0xff, 0x80, 0, 0, 0, 0, 0, 0, 0); // 0x7fff8000000000000000 = NaN
value =
Float80DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Float10DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Assert.assertEquals(ff.getBigNaN(false), value);
Assert.assertEquals("NaN", ff.toDecimalString(value, true));
@ -57,13 +56,13 @@ public class Float80DataTypeTest extends AbstractGTest {
bytes = bytes(0x3c, 1, 0x80, 0, 0, 0, 0, 0, 0, 0);
value =
Float80DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Float10DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Assert.assertEquals("2.22507385850720138E-308",
ff.toDecimalString(value, true));
bytes = bytes(0xbc, 1, 0x80, 0, 0, 0, 0, 0, 0, 0);
value =
Float80DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Float10DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Assert.assertEquals("-2.22507385850720138E-308",
ff.toDecimalString(value, true));
@ -71,26 +70,26 @@ public class Float80DataTypeTest extends AbstractGTest {
bytes = bytes(0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
value =
Float80DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Float10DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
assertEquals(ff.minValue, value);
Assert.assertEquals("3.6E-4951", ff.toDecimalString(value, true));
bytes = bytes(0x80, 0, 0, 0, 0, 0, 0, 0, 0, 1);
value =
Float80DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Float10DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Assert.assertEquals("-3.6E-4951", ff.toDecimalString(value, true));
// Really big values maximum - approaches -infinity
bytes = bytes(0x7f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff);
value =
Float80DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Float10DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
assertEquals(ff.maxValue, value);
Assert.assertEquals("1.18973149535723177E+4932", ff.toDecimalString(value, true));
bytes = bytes(0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff);
value =
Float80DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Float10DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Assert.assertEquals("-1.18973149535723177E+4932", ff.toDecimalString(value, true));
// Values within the range of Double
@ -100,12 +99,12 @@ public class Float80DataTypeTest extends AbstractGTest {
bytes = bytes(0x40, 0, 0xc9, 0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc0, 0);
value =
Float80DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Float10DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Assert.assertEquals("3.14159265358979312", ff.toDecimalString(value, true));
bytes = bytes(0xc0, 0, 0xc9, 0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc0, 0);
value =
Float80DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Float10DataType.dataType.getValue(new ByteMemBufferImpl(null, bytes, true), null, 10);
Assert.assertEquals("-3.14159265358979312", ff.toDecimalString(value, true));
}
@ -123,36 +122,36 @@ public class Float80DataTypeTest extends AbstractGTest {
byte[] bytes = bytes(0x7f, 0xff, 0, 0, 0, 0, 0, 0, 0, 0); // 0x7fff0000000000000000 = +infinity
assertArrayEquals(bytes,
Float80DataType.dataType.encodeValue(ff.getBigFloat("+Infinity"), BE, null, -1));
Float10DataType.dataType.encodeValue(ff.getBigFloat("+Infinity"), BE, null, -1));
bytes = bytes(0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0); // 0xffff0000000000000000 = -infinity
assertArrayEquals(bytes,
Float80DataType.dataType.encodeValue(ff.getBigFloat("-Infinity"), BE, null, -1));
Float10DataType.dataType.encodeValue(ff.getBigFloat("-Infinity"), BE, null, -1));
bytes = bytes(0x7f, 0xff, 0x80, 0, 0, 0, 0, 0, 0, 0); // 0x7fff8000000000000000 = NaN
assertArrayEquals(bytes,
Float80DataType.dataType.encodeValue(ff.getBigFloat("NaN"), BE, null, -1));
Float10DataType.dataType.encodeValue(ff.getBigFloat("NaN"), BE, null, -1));
// NOTE: Multiple byte[] values can render the same decimal string
bytes = Float80DataType.dataType
bytes = Float10DataType.dataType
.encodeValue(ff.getBigFloat("5.04315471466814026E-4932"), BE, null, -1);
assertEquals("5.04315471466814026E-4932", Float80DataType.dataType
assertEquals("5.04315471466814026E-4932", Float10DataType.dataType
.getRepresentation(new ByteMemBufferImpl(null, bytes, true), null, -1));
bytes = Float80DataType.dataType.encodeValue(ff.getBigFloat("-5.04315471466814026E-4932"),
bytes = Float10DataType.dataType.encodeValue(ff.getBigFloat("-5.04315471466814026E-4932"),
BE, null, -1);
assertEquals("-5.04315471466814026E-4932", Float80DataType.dataType
assertEquals("-5.04315471466814026E-4932", Float10DataType.dataType
.getRepresentation(new ByteMemBufferImpl(null, bytes, true), null, -1));
bytes = Float80DataType.dataType
bytes = Float10DataType.dataType
.encodeValue(ff.getBigFloat("8.92298621517923824E+4931"), BE, null, -1);
assertEquals("8.92298621517923824E+4931", Float80DataType.dataType
assertEquals("8.92298621517923824E+4931", Float10DataType.dataType
.getRepresentation(new ByteMemBufferImpl(null, bytes, true), null, -1));
bytes = Float80DataType.dataType.encodeValue(ff.getBigFloat("-8.92298621517923824E+4931"),
bytes = Float10DataType.dataType.encodeValue(ff.getBigFloat("-8.92298621517923824E+4931"),
BE, null, -1);
assertEquals("-8.92298621517923824E+4931", Float80DataType.dataType
assertEquals("-8.92298621517923824E+4931", Float10DataType.dataType
.getRepresentation(new ByteMemBufferImpl(null, bytes, true), null, -1));
}