Class FpMulHardToDRoundIterator
- java.lang.Object
-
- ru.ispras.testbase.knowledge.floating.mul.FpMulHardToDRoundIterator
-
- All Implemented Interfaces:
Iterator<GeneratorResult<FpNumber>>
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:
- M. Parks. Number-Theoretic Test Generation for Directed Rounding. IEEE Transactions on Computers, Volume 49. 2000.
We seek n-bit integers
x
andy
from2^(n-1) + 1
to2^n-1
whose product is as close as possible to a directed rounding boundary:x*y = 2^(n-i)*p + k
, wherei = 0
or1
,k
is a small integer (positive or negative), andp
is an n-bit integer.Given an odd
y
in[2^(n-1)+1, 2^n-1]
and smallk > 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 Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Constructor Detail
-
FpMulHardToDRoundIterator
public FpMulHardToDRoundIterator(FpFormat format, long minY, long maxY, int numY, int maxK, int maxT)
Constructs a square root hard-to-round iterator.- Parameters:
format
- the format.minY
- the minimaly
value.maxY
- the maximaly
value.numY
- the number ofy
values.maxK
- the maximalk
value.maxT
- the maximalt
value.
-
FpMulHardToDRoundIterator
public FpMulHardToDRoundIterator(FpFormat format)
Constructs a square root hard-to-round iterator.- Parameters:
format
- the format.
-
-
Method Detail
-
init
public void init()
Description copied from interface:Iterator
Initializes the iterator.- Specified by:
init
in interfaceIterator<GeneratorResult<FpNumber>>
-
hasValue
public boolean hasValue()
Description copied from interface:Iterator
Checks if the iterator is not exhausted (a value is available).- Specified by:
hasValue
in interfaceIterator<GeneratorResult<FpNumber>>
- Returns:
true
if the iterator is not exhausted;false
otherwise.
-
value
public GeneratorResult<FpNumber> value()
Description copied from interface:Iterator
Returns the current value of the iterator.- Specified by:
value
in interfaceIterator<GeneratorResult<FpNumber>>
- Returns:
- the current value of the iterator.
-
next
public void next()
Description copied from interface:Iterator
Makes an iteration.- Specified by:
next
in interfaceIterator<GeneratorResult<FpNumber>>
-
stop
public void stop()
Description copied from interface:Iterator
Stops the iterator.- Specified by:
stop
in interfaceIterator<GeneratorResult<FpNumber>>
-
clone
public FpMulHardToDRoundIterator clone()
Description copied from interface:Iterator
Creates a copy of the iterator.- Specified by:
clone
in interfaceIterator<GeneratorResult<FpNumber>>
- Overrides:
clone
in classjava.lang.Object
- Returns:
- A copy of the iterator.
-
-