If the value of the first truncated digit is > 5,
the bignum should be rounded up. But it may be rounded down.
===== Here is the minimized test demonstrating the bug =====
import java.lang.Bignum;
class java_lang_Bignum_setRoundingOption {
public static void main(String args[]) {
Bignum.setRoundingOption(Bignum.ROUND_STATISTICAL);
Bignum b=new Bignum("1234.566",2);
System.out.println(b); //should print "1234.57"
}
}
==== Here is the output of the test ====
1234.56
==== Here is the part of the specification ====
public static void setRoundingOption(int val)
Sets the rounding option for all Bignum's in a program; the
default rounding option is ROUND_ABOVE_4.
All Bignum computation is done using an extra digit of precision
which is truncated prior to returning the result. The rounding
option determines how the value of this extra digit affects the
returned value. Rounding also applies when the scale of a
Bignum is reduced; here, rounding defines how the value of the
most significant truncated digit affects the result.
If rounding causes the least signifcant digit of a result to be
incremented by 1, we say the result has been 'rounded up'. If
the least signficant digit of a result is left as is, we say the result
has been 'rounded down'.
The following rounding options are provided:
NO_ROUNDING:
All results are rounded down regardless of the value of
the most significant truncated digit. For example, 1.999
would round to 1.99.
ROUND_ABOVE_4:
If the value of the most significant truncated digit is > 4,
the result is rounded up; otherwise, the result is rounded
down. For example, 1.994 would round down to 1.99 and
1.995 would round up to 2.00
ROUND_ABOVE_5:
If the value of the most significant truncated digit is > 5,
the result is rounded up; otherwise, the result is rounded
down. For example, 1.995 would round down to 1.99 and
1.996 would round up to 2.00
ROUND_ALWAYS :
If the value of the most significant truncated digit is > 0,
the result is rounded up; otherwise, the result is rounded
down. For example, 1.990 would round down to 1.99 and
1.991 would round up to 2.00.
ROUND_STATISTICAL :
If the value of the most significant truncated digit is > 5,
the result is rounded up. If the value of the most
significant truncated digit is < 5, the result is rounded
down. If the value of the most significant truncated digit is
= 5, the result is rounded down if the remaining least
significant digit is even; if it's odd the result is rounded
up. For example, 1.994 would round down to 1.99; 1.996
would round up to 2.00; 1.985 would round down to 1.98;
and, 1.995 would round up to 2.00. This option is used to
help reduce systematic rounding bias. See Bevington
and Robinson, 'Data Reduction and Error Analysis for the
Physical Sciences', pp. 4, McGraw Hill, Inc., (1992).
Parameters:
val - The rounding option to use for all Bignum's.
the bignum should be rounded up. But it may be rounded down.
===== Here is the minimized test demonstrating the bug =====
import java.lang.Bignum;
class java_lang_Bignum_setRoundingOption {
public static void main(String args[]) {
Bignum.setRoundingOption(Bignum.ROUND_STATISTICAL);
Bignum b=new Bignum("1234.566",2);
System.out.println(b); //should print "1234.57"
}
}
==== Here is the output of the test ====
1234.56
==== Here is the part of the specification ====
public static void setRoundingOption(int val)
Sets the rounding option for all Bignum's in a program; the
default rounding option is ROUND_ABOVE_4.
All Bignum computation is done using an extra digit of precision
which is truncated prior to returning the result. The rounding
option determines how the value of this extra digit affects the
returned value. Rounding also applies when the scale of a
Bignum is reduced; here, rounding defines how the value of the
most significant truncated digit affects the result.
If rounding causes the least signifcant digit of a result to be
incremented by 1, we say the result has been 'rounded up'. If
the least signficant digit of a result is left as is, we say the result
has been 'rounded down'.
The following rounding options are provided:
NO_ROUNDING:
All results are rounded down regardless of the value of
the most significant truncated digit. For example, 1.999
would round to 1.99.
ROUND_ABOVE_4:
If the value of the most significant truncated digit is > 4,
the result is rounded up; otherwise, the result is rounded
down. For example, 1.994 would round down to 1.99 and
1.995 would round up to 2.00
ROUND_ABOVE_5:
If the value of the most significant truncated digit is > 5,
the result is rounded up; otherwise, the result is rounded
down. For example, 1.995 would round down to 1.99 and
1.996 would round up to 2.00
ROUND_ALWAYS :
If the value of the most significant truncated digit is > 0,
the result is rounded up; otherwise, the result is rounded
down. For example, 1.990 would round down to 1.99 and
1.991 would round up to 2.00.
ROUND_STATISTICAL :
If the value of the most significant truncated digit is > 5,
the result is rounded up. If the value of the most
significant truncated digit is < 5, the result is rounded
down. If the value of the most significant truncated digit is
= 5, the result is rounded down if the remaining least
significant digit is even; if it's odd the result is rounded
up. For example, 1.994 would round down to 1.99; 1.996
would round up to 2.00; 1.985 would round down to 1.98;
and, 1.995 would round up to 2.00. This option is used to
help reduce systematic rounding bias. See Bevington
and Robinson, 'Data Reduction and Error Analysis for the
Physical Sciences', pp. 4, McGraw Hill, Inc., (1992).
Parameters:
val - The rounding option to use for all Bignum's.