Class FloatFormat

java.lang.Object
ghidra.pcode.floatformat.FloatFormat

public class FloatFormat extends Object
FloatFormat provides IEEE 754 floating-point encoding formats in support of floating-point data types and floating-point emulation. A combination of Java float/double and BigFloat are used to facilitate floating-point operations.
  • Field Details

    • maxValue

      public final BigFloat maxValue
      A constant holding the largest positive finite value
    • minValue

      public final BigFloat minValue
      A constant holding the smallest positive normal value
  • Method Details

    • getSize

      public int getSize()
    • getMaxBigFloat

      public BigFloat getMaxBigFloat()
      Get the maximum finite BigFloat value for this format
      Returns:
      maximum finite BigFloat value
    • getMinBigFloat

      public BigFloat getMinBigFloat()
      Get the minimum finite subnormal BigFloat value for this format
      Returns:
      minimum finite subnormal BigFloat value
    • getZeroEncoding

      public long getZeroEncoding(boolean sgn)
    • getInfinityEncoding

      public long getInfinityEncoding(boolean sgn)
    • getBigZeroEncoding

      public BigInteger getBigZeroEncoding(boolean sgn)
    • getBigZero

      public BigFloat getBigZero(boolean sgn)
    • getBigInfinityEncoding

      public BigInteger getBigInfinityEncoding(boolean sgn)
    • getBigInfinity

      public BigFloat getBigInfinity(boolean sgn)
    • getNaNEncoding

      public long getNaNEncoding(boolean sgn)
    • getBigNaNEncoding

      public BigInteger getBigNaNEncoding(boolean sgn)
    • getBigNaN

      public BigFloat getBigNaN(boolean sgn)
    • getBigFloat

      public BigFloat getBigFloat(float f)
    • getBigFloat

      public BigFloat getBigFloat(double d)
    • decodeBigFloat

      public BigFloat decodeBigFloat(long encoding)
      Decode encoding to a BigFloat using this format. The method decodeBigFloat(BigInteger) should be used for encodings larger than 8 bytes.
      Parameters:
      encoding - the encoding
      Returns:
      the decoded value as a BigFloat
    • decodeHostFloat

      public double decodeHostFloat(long encoding)
    • decodeBigFloat

      public BigFloat decodeBigFloat(BigInteger encoding)
    • getEncoding

      public long getEncoding(double host)
    • getEncoding

      public BigInteger getEncoding(BigFloat value)
    • round

      public BigDecimal round(BigFloat bigFloat)
      Round bigFloat using this format's displayContext.
      Parameters:
      bigFloat - any BigFloat
      Returns:
      a BigDecimal rounded according to this format's displayContext
    • toDecimalString

      public String toDecimalString(BigFloat bigFloat)
      Perform appropriate rounding and conversion to BigDecimal prior to generating a formatted decimal string of the specified BigFloat value.
      Parameters:
      bigFloat - value
      Returns:
      decimal string representation
    • toDecimalString

      public String toDecimalString(BigFloat bigFloat, boolean compact)
      Perform appropriate rounding and conversion to BigDecimal prior to generating a formatted decimal string of the specified BigFloat value.
      Parameters:
      bigFloat - value
      compact - if true the precision will be reduced to a form which is still equivalent at the binary encoding level for this format. Enabling this will incur additional overhead.
      Returns:
      decimal string representation
    • toBigFloat

      public static BigFloat toBigFloat(float f)
      Convert a native float to BigFloat using 4-byte IEEE 754 encoding
      Parameters:
      f - a float
      Returns:
      BigFloat equal to f
    • toBigFloat

      public static BigFloat toBigFloat(double d)
      Convert a native double to BigFloat using 8-byte IEEE 754 encoding
      Parameters:
      d - a double
      Returns:
      BigFloat equal to f
    • opEqual

      public long opEqual(long a, long b)
    • opEqual

      public BigInteger opEqual(BigInteger a, BigInteger b)
    • opNotEqual

      public long opNotEqual(long a, long b)
    • opNotEqual

      public BigInteger opNotEqual(BigInteger a, BigInteger b)
    • opLess

      public long opLess(long a, long b)
    • opLess

      public BigInteger opLess(BigInteger a, BigInteger b)
    • opLessEqual

      public long opLessEqual(long a, long b)
    • opLessEqual

      public BigInteger opLessEqual(BigInteger a, BigInteger b)
    • opNan

      public long opNan(long a)
    • opNan

      public BigInteger opNan(BigInteger a)
    • opAdd

      public long opAdd(long a, long b)
    • opAdd

      public BigInteger opAdd(BigInteger a, BigInteger b)
    • opSub

      public long opSub(long a, long b)
    • opSub

      public BigInteger opSub(BigInteger a, BigInteger b)
    • opDiv

      public long opDiv(long a, long b)
    • opDiv

      public BigInteger opDiv(BigInteger a, BigInteger b)
    • opMult

      public long opMult(long a, long b)
    • opMult

      public BigInteger opMult(BigInteger a, BigInteger b)
    • opNeg

      public long opNeg(long a)
    • opNeg

      public BigInteger opNeg(BigInteger a)
    • opAbs

      public long opAbs(long a)
    • opAbs

      public BigInteger opAbs(BigInteger a)
    • opSqrt

      public long opSqrt(long a)
    • opSqrt

      public BigInteger opSqrt(BigInteger a)
    • opInt2Float

      public long opInt2Float(long a, int sizein)
    • opInt2Float

      public BigInteger opInt2Float(BigInteger a, int sizein, boolean signed)
    • opFloat2Float

      public long opFloat2Float(long a, FloatFormat outformat)
    • opFloat2Float

      public BigInteger opFloat2Float(BigInteger a, FloatFormat outformat)
    • opTrunc

      public long opTrunc(long a, int sizeout)
    • opTrunc

      public BigInteger opTrunc(BigInteger a, int sizeout)
    • opCeil

      public long opCeil(long a)
    • opCeil

      public BigInteger opCeil(BigInteger a)
    • opFloor

      public long opFloor(long a)
    • opFloor

      public BigInteger opFloor(BigInteger a)
    • opRound

      public long opRound(long a)
    • opRound

      public BigInteger opRound(BigInteger a)
    • getBigFloat

      public BigFloat getBigFloat(BigInteger value)
    • getBigFloat

      public BigFloat getBigFloat(String string) throws NumberFormatException
      Constructs a BigFloat initialized to the value represented by the specified decimal String, as performed by BigDecimal(String). Other values permitted are (case-insenstive): "NaN", "Infinity", "+Infinity", "-Infinity" (See BigFloat.NAN, BigFloat.INFINITY, BigFloat.POSITIVE_INFINITY, BigFloat.NEGATIVE_INFINITY).
      Parameters:
      string - the string to be parsed.
      Returns:
      value as a BigFloat
      Throws:
      NullPointerException - if the string is null
      NumberFormatException - if the string parse fails.
    • getBigFloat

      public BigFloat getBigFloat(BigDecimal value)
      Constructs a BigFloat initialized to the value represented by the specified BigDecimal.
      Parameters:
      value - the decimal value.
      Returns:
      value as a BigFloat
      Throws:
      NullPointerException - if the string is null
      NumberFormatException - if the string parse fails.