|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbyucc.jhdl.Logic.Modules.FloatingPoint.helpers.FloatBV
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.
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 |
protected static final int IEEE754_DOUBLE_WIDTH
protected static final int IEEE754_DOUBLE_EXPONENT_WIDTH
protected static final int IEEE754_DOUBLE_SIGNIFICAND_WIDTH
protected static final int IEEE754_DOUBLE_INFINITY_EXPONENT
protected static final int IEEE754_DOUBLE_BIAS
protected static final int IEEE754_SINGLE_WIDTH
protected static final int IEEE754_SINGLE_EXPONENT_WIDTH
protected static final int IEEE754_SINGLE_SIGNIFICAND_WIDTH
protected static final int IEEE754_SINGLE_INFINITY_EXPONENT
protected static final int IEEE754_SINGLE_BIAS
Constructor Detail |
public FloatBV(int width, int expWidth, long value)
width
- The total number of bits in the floating-point representationexpWidth
- The number of bits of exponentvalue
- The initial valuepublic FloatBV(int expWidth, BV bv, boolean wrapper)
expWidth
- The exponent width of the FloatBV.
The total width will be the width of the original bv
.bv
- The BV to copy or referencewrapper
- 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 |
public double doubleValue()
public float floatValue() throws FloatBV.FPException
FloatBV.FPException
public static float floatValue(BV floatImage, int numExpBits)
floatImage
- The BV containing the packed floating-point value.numExpBits
- The number of bits allocated for the exponent.
public java.lang.String toRawBinaryString()
[1 0111 1.1000]
" represents -1.5.
public BV getBV()
public int getWidth()
public FloatBV setValue(double value)
expWidth
exponent bits,
and the remaining bits will be the significand
(without the implicit leading '1' of the
standard floating point significand).
value
- A floating point value to be converted.
public FloatBV setValueToFixed(BV fixed, int fixedExponent)
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.
public FloatBV setValueToRandom(java.util.Random random)
random
- A random number generator.
public static void setValueToRandom(BV bv, java.util.Random random)
random
- A random number generator.public static boolean isNegative(BV floatImage)
public static int log2(int value)
public static java.math.BigInteger shiftRightAndRound(java.math.BigInteger val, int n)
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.
public static int getExponent(BV floatImage, int numExpBits)
floatImage
- The BV containing the packed floating-point value.numExpBits
- The number of bits allocated for the exponent
in floatImage.public static int getBias(int numExpBits)
numExpBits
- The number of bits allocated for the exponent.public static java.math.BigInteger getSignificand(BV floatImage, int numExpBits)
floatImage
- The BV containing the packed floating-point value.numExpBits
- The number of bits allocated for the exponent
in floatImage.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |