byucc.jhdl.Logic.Modules.FloatingPoint.helpers
Class FloatBV

java.lang.Object
  extended bybyucc.jhdl.Logic.Modules.FloatingPoint.helpers.FloatBV

public class FloatBV
extends java.lang.Object

A packed floating-point representation for variable-precision floating-point values. FloatBV cannot store unnormalized values, although some operations use intermediate values that are not normalized.

Since:
June 30, 2001
Version:
$Revision: 1.9 $
Author:
Aaron Stewart, Brent Nelson , Nathan Kitchen
See Also:
BV

Nested Class Summary
static class FloatBV.FPException
           
static class FloatBV.FPOverflowException
           
static class FloatBV.RoundOverflowException
          An exception that occurs when rounding causes a number to no longer be normalized.
 
Field Summary
protected static int IEEE754_DOUBLE_BIAS
           
protected static int IEEE754_DOUBLE_EXPONENT_WIDTH
           
protected static int IEEE754_DOUBLE_INFINITY_EXPONENT
           
protected static int IEEE754_DOUBLE_SIGNIFICAND_WIDTH
           
protected static int IEEE754_DOUBLE_WIDTH
           
protected static int IEEE754_SINGLE_BIAS
           
protected static int IEEE754_SINGLE_EXPONENT_WIDTH
           
protected static int IEEE754_SINGLE_INFINITY_EXPONENT
           
protected static int IEEE754_SINGLE_SIGNIFICAND_WIDTH
           
protected static int IEEE754_SINGLE_WIDTH
           
 
Constructor Summary
FloatBV(int expWidth, BV bv, boolean wrapper)
          Constructs a new FloatBV based on a BV.
FloatBV(int width, int expWidth, long value)
          Constructs a new FloatBV.
 
Method Summary
 double doubleValue()
          Returns a double representation of a custom-sized floating point BV.
 float floatValue()
          Returns a single-precision floating-point representation of a FloatBV.
static float floatValue(BV floatImage, int numExpBits)
          Returns the single-precision floating-point value of a floating-point BV.
static int getBias(int numExpBits)
          Returns the bias associated with floating-point values with the specified exponent width.
 BV getBV()
          Returns the FloatBV as a regular BV.
static int getExponent(BV floatImage, int numExpBits)
          Extracts the unbiased exponent from a floating-point value stored in a BV.
static java.math.BigInteger getSignificand(BV floatImage, int numExpBits)
          Returns the significand of the packed floating-point value.
 int getWidth()
           
static boolean isNegative(BV floatImage)
          Returns the sign bit (the msb) of this floating-point BV.
static int log2(int value)
          Returns the minimum whole number of bits required to represent the value.
 FloatBV setValue(double value)
          Sets the BV to a floating point value.
 FloatBV setValueToFixed(BV fixed, int fixedExponent)
          Converts a fixed-point number to floating-point and sets this FloatBV to that value.
static void setValueToRandom(BV bv, java.util.Random random)
          Sets the BV value to a random bit pattern.
 FloatBV setValueToRandom(java.util.Random random)
          Sets the BV value to a random bit pattern.
static java.math.BigInteger shiftRightAndRound(java.math.BigInteger val, int n)
          Returns the BigInteger derived by shifting val to the right n bits, rounding as necessary.
 java.lang.String toRawBinaryString()
          Returns a string representation of the bits of the FloatBV, separated into sign, exponent, and significand.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IEEE754_DOUBLE_WIDTH

protected static final int IEEE754_DOUBLE_WIDTH
See Also:
Constant Field Values

IEEE754_DOUBLE_EXPONENT_WIDTH

protected static final int IEEE754_DOUBLE_EXPONENT_WIDTH
See Also:
Constant Field Values

IEEE754_DOUBLE_SIGNIFICAND_WIDTH

protected static final int IEEE754_DOUBLE_SIGNIFICAND_WIDTH
See Also:
Constant Field Values

IEEE754_DOUBLE_INFINITY_EXPONENT

protected static final int IEEE754_DOUBLE_INFINITY_EXPONENT
See Also:
Constant Field Values

IEEE754_DOUBLE_BIAS

protected static final int IEEE754_DOUBLE_BIAS
See Also:
Constant Field Values

IEEE754_SINGLE_WIDTH

protected static final int IEEE754_SINGLE_WIDTH
See Also:
Constant Field Values

IEEE754_SINGLE_EXPONENT_WIDTH

protected static final int IEEE754_SINGLE_EXPONENT_WIDTH
See Also:
Constant Field Values

IEEE754_SINGLE_SIGNIFICAND_WIDTH

protected static final int IEEE754_SINGLE_SIGNIFICAND_WIDTH
See Also:
Constant Field Values

IEEE754_SINGLE_INFINITY_EXPONENT

protected static final int IEEE754_SINGLE_INFINITY_EXPONENT
See Also:
Constant Field Values

IEEE754_SINGLE_BIAS

protected static final int IEEE754_SINGLE_BIAS
See Also:
Constant Field Values
Constructor Detail

FloatBV

public FloatBV(int width,
               int expWidth,
               long value)
Constructs a new FloatBV.

Parameters:
width - The total number of bits in the floating-point representation
expWidth - The number of bits of exponent
value - The initial value

FloatBV

public FloatBV(int expWidth,
               BV bv,
               boolean wrapper)
Constructs a new FloatBV based on a BV.

Parameters:
expWidth - The exponent width of the FloatBV. The total width will be the width of the original bv.
bv - The BV to copy or reference
wrapper - If false, the new FloatBV will copy the value of bv; If true, the new FloatBV will reference the original bv, so that changes to the FloatBV will affect bv also.
Method Detail

doubleValue

public double doubleValue()
Returns a double representation of a custom-sized floating point BV.

Returns:
the double representation of the BV.
Since:
7/09/2001

floatValue

public float floatValue()
                 throws FloatBV.FPException
Returns a single-precision floating-point representation of a FloatBV.

Returns:
the float representation of the BV
Throws:
FloatBV.FPException
Since:
7/11/2001

floatValue

public static float floatValue(BV floatImage,
                               int numExpBits)
Returns the single-precision floating-point value of a floating-point BV.

Parameters:
floatImage - The BV containing the packed floating-point value.
numExpBits - The number of bits allocated for the exponent.
Returns:
the value of the floating-point BV, rounded if necessary.
Since:
August 2, 2001

toRawBinaryString

public java.lang.String toRawBinaryString()
Returns a string representation of the bits of the FloatBV, separated into sign, exponent, and significand. Example: "[1 0111 1.1000]" represents -1.5.

Returns:
A string representation of the bits in the floating-point BV.

getBV

public BV getBV()
Returns the FloatBV as a regular BV. Example: wire.putBV (this, myFloatBV.getBV());


getWidth

public int getWidth()

setValue

public FloatBV setValue(double value)
Sets the BV to a floating point value. The floating point representation will have a sign bit and expWidth exponent bits, and the remaining bits will be the significand (without the implicit leading '1' of the standard floating point significand).

Parameters:
value - A floating point value to be converted.
Returns:
this, to allow chaining or nesting of operations.

setValueToFixed

public FloatBV setValueToFixed(BV fixed,
                               int fixedExponent)
Converts a fixed-point number to floating-point and sets this FloatBV to that value. The result is rounded if the floating-point precision is not wide enough to store the exact fixed-point value.

Parameters:
fixed - An fixed-point number, represented as an integer. The BV may be signed or unsigned. See BV, BV.setIsSigned(boolean), BV.getIsSigned().

Note: If fixed is the lowest negative value, it may require rounding even if the floating-point significand is otherwise wide enough to hold the value. This is because of an issue with conversion from two's complement to signed-magnitude notation. The lowest negative value of a two's complement representation requires one more bit in signed-magnitude format.

Example: (signed two's complement) 1111 = -8, but (signed-magnitude) 1 1000 = -8.

fixedExponent - A base-two exponent for fixed, so that the true value is fixed * 2fixedExponent. If fixedExponent is positive, it moves the radix point to the right and pads the value with zeros: xxxx000, etc. If fixedExponent is negative, it moves the radix point to the left: x.xxx, etc.
Returns:
this To allow chaining of operations

setValueToRandom

public FloatBV setValueToRandom(java.util.Random random)
Sets the BV value to a random bit pattern.

Parameters:
random - A random number generator.
Returns:
this, to allow chaining or nesting of operations.

setValueToRandom

public static void setValueToRandom(BV bv,
                                    java.util.Random random)
Sets the BV value to a random bit pattern.

Parameters:
random - A random number generator.

isNegative

public static boolean isNegative(BV floatImage)
Returns the sign bit (the msb) of this floating-point BV.

Returns:
true if the sign bit is set (negative).

log2

public static int log2(int value)
Returns the minimum whole number of bits required to represent the value. Or in other words, (floor(log2(value))) + 1.


shiftRightAndRound

public static java.math.BigInteger shiftRightAndRound(java.math.BigInteger val,
                                                      int n)
Returns the BigInteger derived by shifting val to the right n bits, rounding as necessary. Rounding is performed using the round-toward-nearest-even mode as specified in the IEEE 754 standard. If n is negative, the number is shifted left instead.


getExponent

public static int getExponent(BV floatImage,
                              int numExpBits)
Extracts the unbiased exponent from a floating-point value stored in a BV.

Parameters:
floatImage - The BV containing the packed floating-point value.
numExpBits - The number of bits allocated for the exponent in floatImage.

getBias

public static int getBias(int numExpBits)
Returns the bias associated with floating-point values with the specified exponent width.

Parameters:
numExpBits - The number of bits allocated for the exponent.

getSignificand

public static java.math.BigInteger getSignificand(BV floatImage,
                                                  int numExpBits)
Returns the significand of the packed floating-point value. This assumes the floating-point value is normal (not zero, etc.)

Parameters:
floatImage - The BV containing the packed floating-point value.
numExpBits - The number of bits allocated for the exponent in floatImage.


Copyright ? 2006 Brigham Young University, Configurable Computing Laboratory. All Rights Reserved.