public final class FpMulHardToDRoundIterator extends java.lang.Object implements Iterator<GeneratorResult<FpNumber>>
FpMulHardToDRoundIterator
implements an iterator of hard-to-round test cases for the
multiplication operation operating in the directed round modes (toward zero, toward plus
infinity, and toward minus infinity).
The implementation is based on the following work of Michael Parks:
We seek n-bit integers x
and y
from 2^(n-1) + 1
to 2^n-1
whose
product is as close as possible to a directed rounding boundary: x*y = 2^(n-i)*p + k
,
where i = 0
or 1
, k
is a small integer (positive or negative), and
p
is an n-bit integer.
Given an odd y
in [2^(n-1)+1, 2^n-1]
and small k > 0
the algorithm is
as follows:
if k is even
x_1 = 0
p_1 = (1/2)*k
else
x_1 = 1
p_1 = (1/2)*(y + k)
end
for j = 2 to n
if p_(j-1) is even
x_j = x_(j-1)
p_j = (1/2)*p_(j-1)
else
x_j = 2^(j-1) + x_(j-1)
p_j = (1/2) * (y + p_(j-1))
end
if (p_(n-1) <= 2^n - 1 - y) or (p_(n-1) is odd)
x = 2^(n-1) + x_(n-1) // CASE 0
end
if p_(n-1) >= 2*y - 2^n + 1
x = 2^n - x_(n-1) // CASE 1
else if p_(n-1) is even
x = 2^n - x_n // CASE 2
end
Constructor and Description |
---|
FpMulHardToDRoundIterator(FpFormat format)
Constructs a square root hard-to-round iterator.
|
FpMulHardToDRoundIterator(FpFormat format,
long minY,
long maxY,
int numY,
int maxK,
int maxT)
Constructs a square root hard-to-round iterator.
|
Modifier and Type | Method and Description |
---|---|
FpMulHardToDRoundIterator |
clone()
Creates a copy of the iterator.
|
boolean |
hasValue()
Checks if the iterator is not exhausted (a value is available).
|
void |
init()
Initializes the iterator.
|
void |
next()
Makes an iteration.
|
void |
stop()
Stops the iterator.
|
GeneratorResult<FpNumber> |
value()
Returns the current value of the iterator.
|
public FpMulHardToDRoundIterator(FpFormat format, long minY, long maxY, int numY, int maxK, int maxT)
format
- the format.minY
- the minimal y
value.maxY
- the maximal y
value.numY
- the number of y
values.maxK
- the maximal k
value.maxT
- the maximal t
value.public FpMulHardToDRoundIterator(FpFormat format)
format
- the format.public void init()
Iterator
init
in interface Iterator<GeneratorResult<FpNumber>>
public boolean hasValue()
Iterator
hasValue
in interface Iterator<GeneratorResult<FpNumber>>
true
if the iterator is not exhausted; false
otherwise.public GeneratorResult<FpNumber> value()
Iterator
value
in interface Iterator<GeneratorResult<FpNumber>>
public void next()
Iterator
next
in interface Iterator<GeneratorResult<FpNumber>>
public void stop()
Iterator
stop
in interface Iterator<GeneratorResult<FpNumber>>
public FpMulHardToDRoundIterator clone()
Iterator
clone
in interface Iterator<GeneratorResult<FpNumber>>
clone
in class java.lang.Object