public class BigDecimal extends Number implements Comparable<BigDecimal>
BigDecimal
consists of an arbitrary precision integer
unscaled value and a 32-bit integer scale. If zero
or positive, the scale is the number of digits to the right of the
decimal point. If negative, the unscaled value of the number is
multiplied by ten to the power of the negation of the scale. The
value of the number represented by the BigDecimal
is
therefore (unscaledValue × 10-scale).
The BigDecimal
class provides operations for
arithmetic, scale manipulation, rounding, comparison, hashing, and
format conversion. The toString()
method provides a
canonical representation of a BigDecimal
.
The BigDecimal
class gives its user complete control
over rounding behavior. If no rounding mode is specified and the
exact result cannot be represented, an exception is thrown;
otherwise, calculations can be carried out to a chosen precision
and rounding mode by supplying an appropriate MathContext
object to the operation. In either case, eight rounding
modes are provided for the control of rounding. Using the
integer fields in this class (such as ROUND_HALF_UP
) to
represent rounding mode is largely obsolete; the enumeration values
of the RoundingMode
enum
, (such as RoundingMode.HALF_UP
) should be used instead.
When a MathContext
object is supplied with a precision
setting of 0 (for example, MathContext.UNLIMITED
),
arithmetic operations are exact, as are the arithmetic methods
which take no MathContext
object. (This is the only
behavior that was supported in releases prior to 5.) As a
corollary of computing the exact result, the rounding mode setting
of a MathContext
object with a precision setting of 0 is
not used and thus irrelevant. In the case of divide, the exact
quotient could have an infinitely long decimal expansion; for
example, 1 divided by 3. If the quotient has a nonterminating
decimal expansion and the operation is specified to return an exact
result, an ArithmeticException
is thrown. Otherwise, the
exact result of the division is returned, as done for other
operations.
When the precision setting is not 0, the rules of
BigDecimal
arithmetic are broadly compatible with selected
modes of operation of the arithmetic defined in ANSI X3.274-1996
and ANSI X3.274-1996/AM 1-2000 (section 7.4). Unlike those
standards, BigDecimal
includes many rounding modes, which
were mandatory for division in BigDecimal
releases prior
to 5. Any conflicts between these ANSI standards and the
BigDecimal
specification are resolved in favor of
BigDecimal
.
Since the same numerical value can have different representations (with different scales), the rules of arithmetic and rounding must specify both the numerical result and the scale used in the result's representation.
In general the rounding modes and precision setting determine
how operations return results with a limited number of digits when
the exact result has more digits (perhaps infinitely many in the
case of division) than the number of digits returned.
First, the
total number of digits to return is specified by the
MathContext
's precision
setting; this determines
the result's precision. The digit count starts from the
leftmost nonzero digit of the exact result. The rounding mode
determines how any discarded trailing digits affect the returned
result.
For all arithmetic operators , the operation is carried out as though an exact intermediate result were first calculated and then rounded to the number of digits specified by the precision setting (if necessary), using the selected rounding mode. If the exact result is not returned, some digit positions of the exact result are discarded. When rounding increases the magnitude of the returned result, it is possible for a new digit position to be created by a carry propagating to a leading "9" digit. For example, rounding the value 999.9 to three digits rounding up would be numerically equal to one thousand, represented as 100×101. In such cases, the new "1" is the leading digit position of the returned result.
Besides a logical exact result, each arithmetic operation has a preferred scale for representing a result. The preferred scale for each operation is listed in the table below.
| Operation | Preferred Scale of Result |
|---|---|
| Add | max(addend.scale(), augend.scale()) |
| Subtract | max(minuend.scale(), subtrahend.scale()) |
| Multiply | multiplier.scale() + multiplicand.scale() |
| Divide | dividend.scale() - divisor.scale() |
1/32
is 0.03125
.
Before rounding, the scale of the logical exact intermediate
result is the preferred scale for that operation. If the exact
numerical result cannot be represented in precision
digits, rounding selects the set of digits to return and the scale
of the result is reduced from the scale of the intermediate result
to the least scale which can represent the precision
digits actually returned. If the exact result can be represented
with at most precision
digits, the representation
of the result with the scale closest to the preferred scale is
returned. In particular, an exactly representable quotient may be
represented in fewer than precision
digits by removing
trailing zeros and decreasing the scale. For example, rounding to
three digits using the floor
rounding mode,
19/100 = 0.19 // integer=19, scale=2
but
21/110 = 0.190 // integer=190, scale=3
Note that for add, subtract, and multiply, the reduction in scale will equal the number of digit positions of the exact result which are discarded. If the rounding causes a carry propagation to create a new high-order digit position, an additional digit of the result is discarded than when no new digit position is created.
Other methods may have slightly different rounding semantics.
For example, the result of the pow
method using the
specified algorithm can
occasionally differ from the rounded mathematical result by more
than one unit in the last place, one ulp.
Two types of operations are provided for manipulating the scale
of a BigDecimal
: scaling/rounding operations and decimal
point motion operations. Scaling/rounding operations (setScale
and round
) return a
BigDecimal
whose value is approximately (or exactly) equal
to that of the operand, but whose scale or precision is the
specified value; that is, they increase or decrease the precision
of the stored number with minimal effect on its value. Decimal
point motion operations (movePointLeft
and
movePointRight
) return a
BigDecimal
created from the operand by moving the decimal
point a specified distance in the specified direction.
For the sake of brevity and clarity, pseudo-code is used
throughout the descriptions of BigDecimal
methods. The
pseudo-code expression (i + j)
is shorthand for "a
BigDecimal
whose value is that of the BigDecimal
i
added to that of the BigDecimal
j
." The pseudo-code expression (i == j)
is
shorthand for "true
if and only if the
BigDecimal
i
represents the same value as the
BigDecimal
j
." Other pseudo-code expressions
are interpreted similarly. Square brackets are used to represent
the particular BigInteger
and scale pair defining a
BigDecimal
value; for example [19, 2] is the
BigDecimal
numerically equal to 0.19 having a scale of 2.
Note: care should be exercised if BigDecimal
objects
are used as keys in a SortedMap
or
elements in a SortedSet
since
BigDecimal
's natural ordering is inconsistent
with equals. See Comparable
, SortedMap
or SortedSet
for more
information.
All methods and constructors for this class throw
NullPointerException
when passed a null
object
reference for any input parameter.
BigInteger
,
MathContext
,
RoundingMode
,
SortedMap
,
SortedSet
,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
static BigDecimal |
ONE
The value 1, with a scale of 0.
|
static int |
ROUND_CEILING
Rounding mode to round towards positive infinity.
|
static int |
ROUND_DOWN
Rounding mode to round towards zero.
|
static int |
ROUND_FLOOR
Rounding mode to round towards negative infinity.
|
static int |
ROUND_HALF_DOWN
Rounding mode to round towards "nearest neighbor"
unless both neighbors are equidistant, in which case round
down.
|
static int |
ROUND_HALF_EVEN
Rounding mode to round towards the "nearest neighbor"
unless both neighbors are equidistant, in which case, round
towards the even neighbor.
|
static int |
ROUND_HALF_UP
Rounding mode to round towards "nearest neighbor"
unless both neighbors are equidistant, in which case round up.
|
static int |
ROUND_UNNECESSARY
Rounding mode to assert that the requested operation has an exact
result, hence no rounding is necessary.
|
static int |
ROUND_UP
Rounding mode to round away from zero.
|
static BigDecimal |
TEN
The value 10, with a scale of 0.
|
static BigDecimal |
ZERO
The value 0, with a scale of 0.
|
| Constructor and Description |
|---|
BigDecimal(BigInteger val)
Translates a
BigInteger into a BigDecimal . |
BigDecimal(BigInteger unscaledVal,
int scale)
Translates a
BigInteger unscaled value and an
int scale into a BigDecimal . |
BigDecimal(BigInteger unscaledVal,
int scale,
MathContext mc)
Translates a
BigInteger unscaled value and an
int scale into a BigDecimal , with rounding
according to the context settings. |
BigDecimal(BigInteger val,
MathContext mc)
Translates a
BigInteger into a BigDecimal
rounding according to the context settings. |
BigDecimal(char[] in)
Translates a character array representation of a
BigDecimal into a BigDecimal , accepting the
same sequence of characters as the BigDecimal(String)
constructor. |
BigDecimal(char[] in,
int offset,
int len)
Translates a character array representation of a
BigDecimal into a BigDecimal , accepting the
same sequence of characters as the BigDecimal(String)
constructor, while allowing a sub-array to be specified. |
BigDecimal(char[] in,
int offset,
int len,
MathContext mc)
Translates a character array representation of a
BigDecimal into a BigDecimal , accepting the
same sequence of characters as the BigDecimal(String)
constructor, while allowing a sub-array to be specified and
with rounding according to the context settings. |
BigDecimal(char[] in,
MathContext mc)
Translates a character array representation of a
BigDecimal into a BigDecimal , accepting the
same sequence of characters as the BigDecimal(String)
constructor and with rounding according to the context
settings. |
BigDecimal(double val)
Translates a
double into a BigDecimal which
is the exact decimal representation of the double 's
binary floating-point value. |
BigDecimal(double val,
MathContext mc)
Translates a
double into a BigDecimal , with
rounding according to the context settings. |
BigDecimal(int val)
Translates an
int into a BigDecimal . |
BigDecimal(int val,
MathContext mc)
Translates an
int into a BigDecimal , with
rounding according to the context settings. |
BigDecimal(long val)
Translates a
long into a BigDecimal . |
BigDecimal(long val,
MathContext mc)
Translates a
long into a BigDecimal , with
rounding according to the context settings. |
BigDecimal(String val)
Translates the string representation of a
BigDecimal
into a BigDecimal . |
BigDecimal(String val,
MathContext mc)
Translates the string representation of a
BigDecimal
into a BigDecimal , accepting the same strings as the
BigDecimal(String) constructor, with rounding
according to the context settings. |
| Modifier and Type | Method and Description |
|---|---|
BigDecimal |
abs()
Returns a
BigDecimal whose value is the absolute value
of this BigDecimal , and whose scale is
this.scale() . |
BigDecimal |
abs(MathContext mc)
Returns a
BigDecimal whose value is the absolute value
of this BigDecimal , with rounding according to the
context settings. |
BigDecimal |
add(BigDecimal augend)
Returns a
BigDecimal whose value is (this +
augend) , and whose scale is max(this.scale(),
augend.scale()) . |
BigDecimal |
add(BigDecimal augend,
MathContext mc)
Returns a
BigDecimal whose value is (this + augend) ,
with rounding according to the context settings. |
byte |
byteValueExact()
Converts this
BigDecimal to a byte , checking
for lost information. |
int |
compareTo(BigDecimal val)
Compares this
BigDecimal with the specified
BigDecimal . |
BigDecimal |
divide(BigDecimal divisor)
Returns a
BigDecimal whose value is (this /
divisor) , and whose preferred scale is (this.scale() -
divisor.scale()) ; if the exact quotient cannot be
represented (because it has a non-terminating decimal
expansion) an ArithmeticException is thrown. |
BigDecimal |
divide(BigDecimal divisor,
int roundingMode)
Returns a
BigDecimal whose value is (this /
divisor) , and whose scale is this.scale() . |
BigDecimal |
divide(BigDecimal divisor,
int scale,
int roundingMode)
Returns a
BigDecimal whose value is (this /
divisor) , and whose scale is as specified. |
BigDecimal |
divide(BigDecimal divisor,
int scale,
RoundingMode roundingMode)
Returns a
BigDecimal whose value is (this /
divisor) , and whose scale is as specified. |
BigDecimal |
divide(BigDecimal divisor,
MathContext mc)
Returns a
BigDecimal whose value is (this /
divisor) , with rounding according to the context settings. |
BigDecimal |
divide(BigDecimal divisor,
RoundingMode roundingMode)
Returns a
BigDecimal whose value is (this /
divisor) , and whose scale is this.scale() . |
BigDecimal[] |
divideAndRemainder(BigDecimal divisor)
Returns a two-element
BigDecimal array containing the
result of divideToIntegralValue followed by the result of
remainder on the two operands. |
BigDecimal[] |
divideAndRemainder(BigDecimal divisor,
MathContext mc)
Returns a two-element
BigDecimal array containing the
result of divideToIntegralValue followed by the result of
remainder on the two operands calculated with rounding
according to the context settings. |
BigDecimal |
divideToIntegralValue(BigDecimal divisor)
Returns a
BigDecimal whose value is the integer part
of the quotient (this / divisor) rounded down. |
BigDecimal |
divideToIntegralValue(BigDecimal divisor,
MathContext mc)
Returns a
BigDecimal whose value is the integer part
of (this / divisor) . |
double |
doubleValue()
Converts this
BigDecimal to a double . |
boolean |
equals(Object x)
Compares this
BigDecimal with the specified
Object for equality. |
float |
floatValue()
Converts this
BigDecimal to a float . |
int |
hashCode()
Returns the hash code for this
BigDecimal . |
int |
intValue()
Converts this
BigDecimal to an int . |
int |
intValueExact()
Converts this
BigDecimal to an int , checking
for lost information. |
long |
longValue()
Converts this
BigDecimal to a long . |
long |
longValueExact()
Converts this
BigDecimal to a long , checking
for lost information. |
BigDecimal |
max(BigDecimal val)
Returns the maximum of this
BigDecimal and val . |
BigDecimal |
min(BigDecimal val)
Returns the minimum of this
BigDecimal and
val . |
BigDecimal |
movePointLeft(int n)
Returns a
BigDecimal which is equivalent to this one
with the decimal point moved n places to the left. |
BigDecimal |
movePointRight(int n)
Returns a
BigDecimal which is equivalent to this one
with the decimal point moved n places to the right. |
BigDecimal |
multiply(BigDecimal multiplicand)
Returns a
BigDecimal whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()) . |
BigDecimal |
multiply(BigDecimal multiplicand,
MathContext mc)
Returns a
BigDecimal whose value is (this ×
multiplicand), with rounding according to the context settings. |
BigDecimal |
negate()
Returns a
BigDecimal whose value is (-this) ,
and whose scale is this.scale() . |
BigDecimal |
negate(MathContext mc)
Returns a
BigDecimal whose value is (-this) ,
with rounding according to the context settings. |
BigDecimal |
plus()
Returns a
BigDecimal whose value is (+this) , and whose
scale is this.scale() . |
BigDecimal |
plus(MathContext mc)
Returns a
BigDecimal whose value is (+this) ,
with rounding according to the context settings. |
BigDecimal |
pow(int n)
Returns a
BigDecimal whose value is
(thisn), The power is computed exactly, to
unlimited precision. |
BigDecimal |
pow(int n,
MathContext mc)
Returns a
BigDecimal whose value is
(thisn). |
int |
precision()
Returns the precision of this
BigDecimal . |
BigDecimal |
remainder(BigDecimal divisor)
Returns a
BigDecimal whose value is (this % divisor) . |
BigDecimal |
remainder(BigDecimal divisor,
MathContext mc)
Returns a
BigDecimal whose value is (this %
divisor) , with rounding according to the context settings. |
BigDecimal |
round(MathContext mc)
Returns a
BigDecimal rounded according to the
MathContext settings. |
int |
scale()
Returns the scale of this
BigDecimal . |
BigDecimal |
scaleByPowerOfTen(int n)
Returns a BigDecimal whose numerical value is equal to
(
this * 10n). |
BigDecimal |
setScale(int newScale)
Returns a
BigDecimal whose scale is the specified
value, and whose value is numerically equal to this
BigDecimal 's. |
BigDecimal |
setScale(int newScale,
int roundingMode)
Returns a
BigDecimal whose scale is the specified
value, and whose unscaled value is determined by multiplying or
dividing this BigDecimal 's unscaled value by the
appropriate power of ten to maintain its overall value. |
BigDecimal |
setScale(int newScale,
RoundingMode roundingMode)
Returns a
BigDecimal whose scale is the specified
value, and whose unscaled value is determined by multiplying or
dividing this BigDecimal 's unscaled value by the
appropriate power of ten to maintain its overall value. |
short |
shortValueExact()
Converts this
BigDecimal to a short , checking
for lost information. |
int |
signum()
Returns the signum function of this
BigDecimal . |
BigDecimal |
stripTrailingZeros()
Returns a
BigDecimal which is numerically equal to
this one but with any trailing zeros removed from the
representation. |
BigDecimal |
subtract(BigDecimal subtrahend)
Returns a
BigDecimal whose value is (this -
subtrahend) , and whose scale is max(this.scale(),
subtrahend.scale()) . |
BigDecimal |
subtract(BigDecimal subtrahend,
MathContext mc)
Returns a
BigDecimal whose value is (this - subtrahend) ,
with rounding according to the context settings. |
BigInteger |
toBigInteger()
Converts this
BigDecimal to a BigInteger . |
BigInteger |
toBigIntegerExact()
Converts this
BigDecimal to a BigInteger ,
checking for lost information. |
String |
toEngineeringString()
Returns a string representation of this
BigDecimal ,
using engineering notation if an exponent is needed. |
String |
toPlainString()
Returns a string representation of this
BigDecimal
without an exponent field. |
String |
toString()
Returns the string representation of this
BigDecimal ,
using scientific notation if an exponent is needed. |
BigDecimal |
ulp()
Returns the size of an ulp, a unit in the last place, of this
BigDecimal . |
BigInteger |
unscaledValue()
Returns a
BigInteger whose value is the unscaled
value of this BigDecimal . |
static BigDecimal |
valueOf(double val)
Translates a
double into a BigDecimal , using
the double 's canonical string representation provided
by the Double.toString(double) method. |
static BigDecimal |
valueOf(long val)
Translates a
long value into a BigDecimal
with a scale of zero. |
static BigDecimal |
valueOf(long unscaledVal,
int scale)
Translates a
long unscaled value and an
int scale into a BigDecimal . |
byteValue, shortValue
public static final BigDecimal ZERO
public static final BigDecimal ONE
public static final BigDecimal TEN
public static final int ROUND_UP
public static final int ROUND_DOWN
public static final int ROUND_CEILING
BigDecimal
is positive, behaves as for
ROUND_UP
; if negative, behaves as for
ROUND_DOWN
. Note that this rounding mode never
decreases the calculated value.public static final int ROUND_FLOOR
BigDecimal
is positive, behave as for
ROUND_DOWN
; if negative, behave as for
ROUND_UP
. Note that this rounding mode never
increases the calculated value.public static final int ROUND_HALF_UP
ROUND_UP
if the discarded fraction is
≥ 0.5; otherwise, behaves as for ROUND_DOWN
. Note
that this is the rounding mode that most of us were taught in
grade school.public static final int ROUND_HALF_DOWN
ROUND_UP
if the discarded
fraction is > 0.5; otherwise, behaves as for
ROUND_DOWN
.public static final int ROUND_HALF_EVEN
ROUND_HALF_UP
if the digit to the left of the
discarded fraction is odd; behaves as for
ROUND_HALF_DOWN
if it's even. Note that this is the
rounding mode that minimizes cumulative error when applied
repeatedly over a sequence of calculations.public static final int ROUND_UNNECESSARY
ArithmeticException
is thrown.public BigDecimal(char[] in, int offset, int len)
BigDecimal
into a BigDecimal
, accepting the
same sequence of characters as the BigDecimal(String)
constructor, while allowing a sub-array to be specified.
Note that if the sequence of characters is already available
within a character array, using this constructor is faster than
converting the char
array to string and using the
BigDecimal(String)
constructor .
in
- char
array that is the source of characters.offset
- first character in the array to inspect.len
- number of characters to consider.NumberFormatException
- if in
is not a valid
representation of a BigDecimal
or the defined subarray
is not wholly within in
.public BigDecimal(char[] in, int offset, int len, MathContext mc)
BigDecimal
into a BigDecimal
, accepting the
same sequence of characters as the BigDecimal(String)
constructor, while allowing a sub-array to be specified and
with rounding according to the context settings.
Note that if the sequence of characters is already available
within a character array, using this constructor is faster than
converting the char
array to string and using the
BigDecimal(String)
constructor .
in
- char
array that is the source of characters.offset
- first character in the array to inspect.len
- number of characters to consider..mc
- the context to use.ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
.NumberFormatException
- if in
is not a valid
representation of a BigDecimal
or the defined subarray
is not wholly within in
.public BigDecimal(char[] in)
BigDecimal
into a BigDecimal
, accepting the
same sequence of characters as the BigDecimal(String)
constructor.
Note that if the sequence of characters is already available
as a character array, using this constructor is faster than
converting the char
array to string and using the
BigDecimal(String)
constructor .
in
- char
array that is the source of characters.NumberFormatException
- if in
is not a valid
representation of a BigDecimal
.public BigDecimal(char[] in, MathContext mc)
BigDecimal
into a BigDecimal
, accepting the
same sequence of characters as the BigDecimal(String)
constructor and with rounding according to the context
settings.
Note that if the sequence of characters is already available
as a character array, using this constructor is faster than
converting the char
array to string and using the
BigDecimal(String)
constructor .
in
- char
array that is the source of characters.mc
- the context to use.ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
.NumberFormatException
- if in
is not a valid
representation of a BigDecimal
.public BigDecimal(String val)
BigDecimal
into a BigDecimal
. The string representation consists
of an optional sign, '+'
( '\u002B') or
'-'
('\u002D'), followed by a sequence of
zero or more decimal digits ("the integer"), optionally
followed by a fraction, optionally followed by an exponent.
The fraction consists of a decimal point followed by zero or more decimal digits. The string must contain at least one digit in either the integer or the fraction. The number formed by the sign, the integer and the fraction is referred to as the significand.
The exponent consists of the character 'e'
('\u0065') or 'E'
('\u0045')
followed by one or more decimal digits. The value of the
exponent must lie between -Integer.MAX_VALUE
(Integer.MIN_VALUE
+1) and Integer.MAX_VALUE
, inclusive.
More formally, the strings this constructor accepts are described by the following grammar:
- BigDecimalString:
- Signopt Significand Exponentopt
- Sign:
+
-
- Significand:
- IntegerPart
.
FractionPartopt.
FractionPart- IntegerPart
- IntegerPart:
- Digits
- FractionPart:
- Digits
- Exponent:
- ExponentIndicator SignedInteger
- ExponentIndicator:
e
E
- SignedInteger:
- Signopt Digits
- Digits:
- Digit
- Digits Digit
- Digit:
- any character for which
Character.isDigit(char)
returnstrue
, including 0, 1, 2 ...
The scale of the returned BigDecimal
will be the
number of digits in the fraction, or zero if the string
contains no decimal point, subject to adjustment for any
exponent; if the string contains an exponent, the exponent is
subtracted from the scale. The value of the resulting scale
must lie between Integer.MIN_VALUE
and
Integer.MAX_VALUE
, inclusive.
The character-to-digit mapping is provided by Character.digit(char, int)
set to convert to radix 10. The
String may not contain any extraneous characters (whitespace,
for example).
Examples:
The value of the returned BigDecimal
is equal to
significand × 10 exponent.
For each string on the left, the resulting representation
[BigInteger
, scale
] is shown on the right.
"0" [0,0] "0.00" [0,2] "123" [123,0] "-123" [-123,0] "1.23E3" [123,-1] "1.23E+3" [123,-1] "12.3E+7" [123,-6] "12.0" [120,1] "12.3" [123,1] "0.00123" [123,5] "-1.23E-12" [-123,14] "1234.5E-4" [12345,5] "0E+7" [0,-7] "-0" [0,0]
Note: For values other than float
and
double
NaN and ±Infinity, this constructor is
compatible with the values returned by Float.toString(float)
and Double.toString(double)
. This is generally the preferred
way to convert a float
or double
into a
BigDecimal, as it doesn't suffer from the unpredictability of
the BigDecimal(double)
constructor.
val
- String representation of BigDecimal
.NumberFormatException
- if val
is not a valid
representation of a BigDecimal
.public BigDecimal(String val, MathContext mc)
BigDecimal
into a BigDecimal
, accepting the same strings as the
BigDecimal(String)
constructor, with rounding
according to the context settings.val
- string representation of a BigDecimal
.mc
- the context to use.ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
.NumberFormatException
- if val
is not a valid
representation of a BigDecimal.public BigDecimal(double val)
double
into a BigDecimal
which
is the exact decimal representation of the double
's
binary floating-point value. The scale of the returned
BigDecimal
is the smallest value such that
(10scale × val) is an integer.
Notes:
new BigDecimal(0.1)
in
Java creates a BigDecimal
which is exactly equal to
0.1 (an unscaled value of 1, with a scale of 1), but it is
actually equal to
0.1000000000000000055511151231257827021181583404541015625.
This is because 0.1 cannot be represented exactly as a
double
(or, for that matter, as a binary fraction of
any finite length). Thus, the value that is being passed
in to the constructor is not exactly equal to 0.1,
appearances notwithstanding.
String
constructor, on the other hand, is
perfectly predictable: writing new BigDecimal("0.1")
creates a BigDecimal
which is exactly equal to
0.1, as one would expect. Therefore, it is generally
recommended that the String constructor be used in preference to this one.
double
must be used as a source for a
BigDecimal
, note that this constructor provides an
exact conversion; it does not give the same result as
converting the double
to a String
using the
Double.toString(double)
method and then using the
BigDecimal(String)
constructor. To get that result,
use the static
valueOf(double)
method.
val
- double
value to be converted to
BigDecimal
.NumberFormatException
- if val
is infinite or NaN.public BigDecimal(double val, MathContext mc)
double
into a BigDecimal
, with
rounding according to the context settings. The scale of the
BigDecimal
is the smallest value such that
(10scale × val) is an integer.
The results of this constructor can be somewhat unpredictable
and its use is generally not recommended; see the notes under
the BigDecimal(double)
constructor.
val
- double
value to be converted to
BigDecimal
.mc
- the context to use.ArithmeticException
- if the result is inexact but the
RoundingMode is UNNECESSARY.NumberFormatException
- if val
is infinite or NaN.public BigDecimal(BigInteger val)
BigInteger
into a BigDecimal
.
The scale of the BigDecimal
is zero.val
- BigInteger
value to be converted to
BigDecimal
.public BigDecimal(BigInteger val, MathContext mc)
BigInteger
into a BigDecimal
rounding according to the context settings. The scale of the
BigDecimal
is zero.val
- BigInteger
value to be converted to
BigDecimal
.mc
- the context to use.ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
.public BigDecimal(BigInteger unscaledVal, int scale)
BigInteger
unscaled value and an
int
scale into a BigDecimal
. The value of
the BigDecimal
is
(unscaledVal × 10-scale).unscaledVal
- unscaled value of the BigDecimal
.scale
- scale of the BigDecimal
.public BigDecimal(BigInteger unscaledVal, int scale, MathContext mc)
BigInteger
unscaled value and an
int
scale into a BigDecimal
, with rounding
according to the context settings. The value of the
BigDecimal
is (unscaledVal ×
10-scale), rounded according to the
precision
and rounding mode settings.unscaledVal
- unscaled value of the BigDecimal
.scale
- scale of the BigDecimal
.mc
- the context to use.ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
.public BigDecimal(int val)
int
into a BigDecimal
. The
scale of the BigDecimal
is zero.val
- int
value to be converted to
BigDecimal
.public BigDecimal(int val, MathContext mc)
int
into a BigDecimal
, with
rounding according to the context settings. The scale of the
BigDecimal
, before any rounding, is zero.val
- int
value to be converted to BigDecimal
.mc
- the context to use.ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
.public BigDecimal(long val)
long
into a BigDecimal
. The
scale of the BigDecimal
is zero.val
- long
value to be converted to BigDecimal
.public BigDecimal(long val, MathContext mc)
long
into a BigDecimal
, with
rounding according to the context settings. The scale of the
BigDecimal
, before any rounding, is zero.val
- long
value to be converted to BigDecimal
.mc
- the context to use.ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
.public static BigDecimal valueOf(long unscaledVal, int scale)
long
unscaled value and an
int
scale into a BigDecimal
. This
"static factory method" is provided in preference to
a (long
, int
) constructor because it
allows for reuse of frequently used BigDecimal
values..unscaledVal
- unscaled value of the BigDecimal
.scale
- scale of the BigDecimal
.BigDecimal
whose value is
(unscaledVal × 10-scale).public static BigDecimal valueOf(long val)
long
value into a BigDecimal
with a scale of zero. This "static factory method"
is provided in preference to a (long
) constructor
because it allows for reuse of frequently used
BigDecimal
values.val
- value of the BigDecimal
.BigDecimal
whose value is val
.public static BigDecimal valueOf(double val)
double
into a BigDecimal
, using
the double
's canonical string representation provided
by the Double.toString(double)
method.
Note: This is generally the preferred way to convert
a double
(or float
) into a
BigDecimal
, as the value returned is equal to that
resulting from constructing a BigDecimal
from the
result of using Double.toString(double)
.
val
- double
to convert to a BigDecimal
.BigDecimal
whose value is equal to or approximately
equal to the value of val
.NumberFormatException
- if val
is infinite or NaN.public BigDecimal add(BigDecimal augend)
BigDecimal
whose value is (this +
augend)
, and whose scale is max(this.scale(),
augend.scale())
.augend
- value to be added to this BigDecimal
.this + augend
public BigDecimal add(BigDecimal augend, MathContext mc)
BigDecimal
whose value is (this + augend)
,
with rounding according to the context settings.
If either number is zero and the precision setting is nonzero then
the other number, rounded if necessary, is used as the result.augend
- value to be added to this BigDecimal
.mc
- the context to use.this + augend
, rounded as necessary.ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
.public BigDecimal subtract(BigDecimal subtrahend)
BigDecimal
whose value is (this -
subtrahend)
, and whose scale is max(this.scale(),
subtrahend.scale())
.subtrahend
- value to be subtracted from this BigDecimal
.this - subtrahend
public BigDecimal subtract(BigDecimal subtrahend, MathContext mc)
BigDecimal
whose value is (this - subtrahend)
,
with rounding according to the context settings.
If subtrahend
is zero then this, rounded if necessary, is used as the
result. If this is zero then the result is subtrahend.negate(mc)
.subtrahend
- value to be subtracted from this BigDecimal
.mc
- the context to use.this - subtrahend
, rounded as necessary.ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
.public BigDecimal multiply(BigDecimal multiplicand)
BigDecimal
whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale())
.multiplicand
- value to be multiplied by this BigDecimal
.this * multiplicand
public BigDecimal multiply(BigDecimal multiplicand, MathContext mc)
BigDecimal
whose value is (this ×
multiplicand), with rounding according to the context settings.multiplicand
- value to be multiplied by this BigDecimal
.mc
- the context to use.this * multiplicand
, rounded as necessary.ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
.public BigDecimal divide(BigDecimal divisor, int scale, int roundingMode)
BigDecimal
whose value is (this /
divisor)
, and whose scale is as specified. If rounding must
be performed to generate a result with the specified scale, the
specified rounding mode is applied.
The new divide(BigDecimal, int, RoundingMode)
method
should be used in preference to this legacy method.
divisor
- value by which this BigDecimal
is to be divided.scale
- scale of the BigDecimal
quotient to be returned.roundingMode
- rounding mode to apply.this / divisor
ArithmeticException
- if divisor
is zero,
roundingMode==ROUND_UNNECESSARY
and
the specified scale is insufficient to represent the result
of the division exactly.IllegalArgumentException
- if roundingMode
does not
represent a valid rounding mode.ROUND_UP
,
ROUND_DOWN
,
ROUND_CEILING
,
ROUND_FLOOR
,
ROUND_HALF_UP
,
ROUND_HALF_DOWN
,
ROUND_HALF_EVEN
,
ROUND_UNNECESSARY
public BigDecimal divide(BigDecimal divisor, int scale, RoundingMode roundingMode)
BigDecimal
whose value is (this /
divisor)
, and whose scale is as specified. If rounding must
be performed to generate a result with the specified scale, the
specified rounding mode is applied.divisor
- value by which this BigDecimal
is to be divided.scale
- scale of the BigDecimal
quotient to be returned.roundingMode
- rounding mode to apply.this / divisor
ArithmeticException
- if divisor
is zero,
roundingMode==RoundingMode.UNNECESSARY
and
the specified scale is insufficient to represent the result
of the division exactly.public BigDecimal divide(BigDecimal divisor, int roundingMode)
BigDecimal
whose value is (this /
divisor)
, and whose scale is this.scale()
. If
rounding must be performed to generate a result with the given
scale, the specified rounding mode is applied.
The new divide(BigDecimal, RoundingMode)
method
should be used in preference to this legacy method.
divisor
- value by which this BigDecimal
is to be divided.roundingMode
- rounding mode to apply.this / divisor
ArithmeticException
- if divisor==0
, or
roundingMode==ROUND_UNNECESSARY
and
this.scale()
is insufficient to represent the result
of the division exactly.IllegalArgumentException
- if roundingMode
does not
represent a valid rounding mode.ROUND_UP
,
ROUND_DOWN
,
ROUND_CEILING
,
ROUND_FLOOR
,
ROUND_HALF_UP
,
ROUND_HALF_DOWN
,
ROUND_HALF_EVEN
,
ROUND_UNNECESSARY
public BigDecimal divide(BigDecimal divisor, RoundingMode roundingMode)
BigDecimal
whose value is (this /
divisor)
, and whose scale is this.scale()
. If
rounding must be performed to generate a result with the given
scale, the specified rounding mode is applied.divisor
- value by which this BigDecimal
is to be divided.roundingMode
- rounding mode to apply.this / divisor
ArithmeticException
- if divisor==0
, or
roundingMode==RoundingMode.UNNECESSARY
and
this.scale()
is insufficient to represent the result
of the division exactly.public BigDecimal divide(BigDecimal divisor)
BigDecimal
whose value is (this /
divisor)
, and whose preferred scale is (this.scale() -
divisor.scale())
; if the exact quotient cannot be
represented (because it has a non-terminating decimal
expansion) an ArithmeticException
is thrown.divisor
- value by which this BigDecimal
is to be divided.this / divisor
ArithmeticException
- if the exact quotient does not have a
terminating decimal expansionpublic BigDecimal divide(BigDecimal divisor, MathContext mc)
BigDecimal
whose value is (this /
divisor)
, with rounding according to the context settings.divisor
- value by which this BigDecimal
is to be divided.mc
- the context to use.this / divisor
, rounded as necessary.ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
or
mc.precision == 0
and the quotient has a
non-terminating decimal expansion.public BigDecimal divideToIntegralValue(BigDecimal divisor)
BigDecimal
whose value is the integer part
of the quotient (this / divisor)
rounded down. The
preferred scale of the result is (this.scale() -
divisor.scale())
.divisor
- value by which this BigDecimal
is to be divided.this / divisor
.ArithmeticException
- if divisor==0
public BigDecimal divideToIntegralValue(BigDecimal divisor, MathContext mc)
BigDecimal
whose value is the integer part
of (this / divisor)
. Since the integer part of the
exact quotient does not depend on the rounding mode, the
rounding mode does not affect the values returned by this
method. The preferred scale of the result is
(this.scale() - divisor.scale())
. An
ArithmeticException
is thrown if the integer part of
the exact quotient needs more than mc.precision
digits.divisor
- value by which this BigDecimal
is to be divided.mc
- the context to use.this / divisor
.ArithmeticException
- if divisor==0
ArithmeticException
- if mc.precision
> 0 and the result
requires a precision of more than mc.precision
digits.public BigDecimal remainder(BigDecimal divisor)
BigDecimal
whose value is (this % divisor)
.
The remainder is given by
this.subtract(this.divideToIntegralValue(divisor).multiply(divisor))
.
Note that this is not the modulo operation (the result can be
negative).
divisor
- value by which this BigDecimal
is to be divided.this % divisor
.ArithmeticException
- if divisor==0
public BigDecimal remainder(BigDecimal divisor, MathContext mc)
BigDecimal
whose value is (this %
divisor)
, with rounding according to the context settings.
The MathContext
settings affect the implicit divide
used to compute the remainder. The remainder computation
itself is by definition exact. Therefore, the remainder may
contain more than mc.getPrecision()
digits.
The remainder is given by
this.subtract(this.divideToIntegralValue(divisor,
mc).multiply(divisor))
. Note that this is not the modulo
operation (the result can be negative).
divisor
- value by which this BigDecimal
is to be divided.mc
- the context to use.this % divisor
, rounded as necessary.ArithmeticException
- if divisor==0
ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
, or mc.precision
> 0 and the result of this.divideToIntgralValue(divisor)
would
require a precision of more than mc.precision
digits.divideToIntegralValue(java.math.BigDecimal, java.math.MathContext)
public BigDecimal[] divideAndRemainder(BigDecimal divisor)
BigDecimal
array containing the
result of divideToIntegralValue
followed by the result of
remainder
on the two operands.
Note that if both the integer quotient and remainder are
needed, this method is faster than using the
divideToIntegralValue
and remainder
methods
separately because the division need only be carried out once.
divisor
- value by which this BigDecimal
is to be divided,
and the remainder computed.BigDecimal
array: the quotient
(the result of divideToIntegralValue
) is the initial element
and the remainder is the final element.ArithmeticException
- if divisor==0
divideToIntegralValue(java.math.BigDecimal, java.math.MathContext)
,
remainder(java.math.BigDecimal, java.math.MathContext)
public BigDecimal[] divideAndRemainder(BigDecimal divisor, MathContext mc)
BigDecimal
array containing the
result of divideToIntegralValue
followed by the result of
remainder
on the two operands calculated with rounding
according to the context settings.
Note that if both the integer quotient and remainder are
needed, this method is faster than using the
divideToIntegralValue
and remainder
methods
separately because the division need only be carried out once.
divisor
- value by which this BigDecimal
is to be divided,
and the remainder computed.mc
- the context to use.BigDecimal
array: the quotient
(the result of divideToIntegralValue
) is the
initial element and the remainder is the final element.ArithmeticException
- if divisor==0
ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
, or mc.precision
> 0 and the result of this.divideToIntgralValue(divisor)
would
require a precision of more than mc.precision
digits.divideToIntegralValue(java.math.BigDecimal, java.math.MathContext)
,
remainder(java.math.BigDecimal, java.math.MathContext)
public BigDecimal pow(int n)
BigDecimal
whose value is
(thisn), The power is computed exactly, to
unlimited precision.
The parameter n
must be in the range 0 through
999999999, inclusive. ZERO.pow(0)
returns ONE
.
Note that future releases may expand the allowable exponent
range of this method.
n
- power to raise this BigDecimal
to.ArithmeticException
- if n
is out of range.public BigDecimal pow(int n, MathContext mc)
BigDecimal
whose value is
(thisn). The current implementation uses
the core algorithm defined in ANSI standard X3.274-1996 with
rounding according to the context settings. In general, the
returned numerical value is within two ulps of the exact
numerical value for the chosen precision. Note that future
releases may use a different algorithm with a decreased
allowable error bound and increased allowable exponent range.
The X3.274-1996 algorithm is:
ArithmeticException
exception is thrown if
abs(n) > 999999999
mc.precision == 0
and n < 0
mc.precision > 0
and n
has more than
mc.precision
decimal digits
n
is zero, ONE
is returned even if
this
is zero, otherwise
n
is positive, the result is calculated via
the repeated squaring technique into a single accumulator.
The individual multiplications with the accumulator use the
same math context settings as in mc
except for a
precision increased to mc.precision + elength + 1
where elength
is the number of decimal digits in
n
.
n
is negative, the result is calculated as if
n
were positive; this value is then divided into one
using the working precision specified above.
n
- power to raise this BigDecimal
to.mc
- the context to use.ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
, or n
is out
of range.public BigDecimal abs()
BigDecimal
whose value is the absolute value
of this BigDecimal
, and whose scale is
this.scale()
.abs(this)
public BigDecimal abs(MathContext mc)
BigDecimal
whose value is the absolute value
of this BigDecimal
, with rounding according to the
context settings.mc
- the context to use.abs(this)
, rounded as necessary.ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
.public BigDecimal negate()
BigDecimal
whose value is (-this)
,
and whose scale is this.scale()
.-this
.public BigDecimal negate(MathContext mc)
BigDecimal
whose value is (-this)
,
with rounding according to the context settings.mc
- the context to use.-this
, rounded as necessary.ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
.public BigDecimal plus()
BigDecimal
whose value is (+this)
, and whose
scale is this.scale()
.
This method, which simply returns this BigDecimal
is included for symmetry with the unary minus method negate()
.
this
.negate()
public BigDecimal plus(MathContext mc)
BigDecimal
whose value is (+this)
,
with rounding according to the context settings.
The effect of this method is identical to that of the round(MathContext)
method.
mc
- the context to use.this
, rounded as necessary. A zero result will
have a scale of 0.ArithmeticException
- if the result is inexact but the
rounding mode is UNNECESSARY
.round(MathContext)
public int signum()
BigDecimal
.BigDecimal
is negative, zero, or positive.public int scale()
BigDecimal
. If zero
or positive, the scale is the number of digits to the right of
the decimal point. If negative, the unscaled value of the
number is multiplied by ten to the power of the negation of the
scale. For example, a scale of -3
means the unscaled
value is multiplied by 1000.BigDecimal
.public int precision()
BigDecimal
. (The
precision is the number of digits in the unscaled value.)
The precision of a zero value is 1.
BigDecimal
.public BigInteger unscaledValue()
BigInteger
whose value is the unscaled
value of this BigDecimal
. (Computes (this *
10this.scale()).)BigDecimal
.public BigDecimal round(MathContext mc)
BigDecimal
rounded according to the
MathContext
settings. If the precision setting is 0 then
no rounding takes place.
The effect of this method is identical to that of the
plus(MathContext)
method.
mc
- the context to use.BigDecimal
rounded according to the
MathContext
settings.ArithmeticException
- if the rounding mode is
UNNECESSARY
and the
BigDecimal
operation would require rounding.plus(MathContext)
public BigDecimal setScale(int newScale, RoundingMode roundingMode)
BigDecimal
whose scale is the specified
value, and whose unscaled value is determined by multiplying or
dividing this BigDecimal
's unscaled value by the
appropriate power of ten to maintain its overall value. If the
scale is reduced by the operation, the unscaled value must be
divided (rather than multiplied), and the value may be changed;
in this case, the specified rounding mode is applied to the
division.
Note that since BigDecimal objects are immutable, calls of
this method do not result in the original object being
modified, contrary to the usual convention of having methods
named setX mutate field X
.
Instead, setScale
returns an object with the proper
scale; the returned object may or may not be newly allocated.
newScale
- scale of the BigDecimal
value to be returned.roundingMode
- The rounding mode to apply.BigDecimal
whose scale is the specified value,
and whose unscaled value is determined by multiplying or
dividing this BigDecimal
's unscaled value by the
appropriate power of ten to maintain its overall value.ArithmeticException
- if roundingMode==UNNECESSARY
and the specified scaling operation would require
rounding.RoundingMode
public BigDecimal setScale(int newScale, int roundingMode)
BigDecimal
whose scale is the specified
value, and whose unscaled value is determined by multiplying or
dividing this BigDecimal
's unscaled value by the
appropriate power of ten to maintain its overall value. If the
scale is reduced by the operation, the unscaled value must be
divided (rather than multiplied), and the value may be changed;
in this case, the specified rounding mode is applied to the
division.
Note that since BigDecimal objects are immutable, calls of
this method do not result in the original object being
modified, contrary to the usual convention of having methods
named setX mutate field X
.
Instead, setScale
returns an object with the proper
scale; the returned object may or may not be newly allocated.
The new setScale(int, RoundingMode)
method should
be used in preference to this legacy method.
newScale
- scale of the BigDecimal
value to be returned.roundingMode
- The rounding mode to apply.BigDecimal
whose scale is the specified value,
and whose unscaled value is determined by multiplying or
dividing this BigDecimal
's unscaled value by the
appropriate power of ten to maintain its overall value.ArithmeticException
- if roundingMode==ROUND_UNNECESSARY
and the specified scaling operation would require
rounding.IllegalArgumentException
- if roundingMode
does not
represent a valid rounding mode.ROUND_UP
,
ROUND_DOWN
,
ROUND_CEILING
,
ROUND_FLOOR
,
ROUND_HALF_UP
,
ROUND_HALF_DOWN
,
ROUND_HALF_EVEN
,
ROUND_UNNECESSARY
public BigDecimal setScale(int newScale)
BigDecimal
whose scale is the specified
value, and whose value is numerically equal to this
BigDecimal
's. Throws an ArithmeticException
if this is not possible.
This call is typically used to increase the scale, in which
case it is guaranteed that there exists a BigDecimal
of the specified scale and the correct value. The call can
also be used to reduce the scale if the caller knows that the
BigDecimal
has sufficiently many zeros at the end of
its fractional part (i.e., factors of ten in its integer value)
to allow for the rescaling without changing its value.
This method returns the same result as the two-argument
versions of setScale
, but saves the caller the trouble
of specifying a rounding mode in cases where it is irrelevant.
Note that since BigDecimal
objects are immutable,
calls of this method do not result in the original
object being modified, contrary to the usual convention of
having methods named setX mutate field
X
. Instead, setScale
returns an
object with the proper scale; the returned object may or may
not be newly allocated.
newScale
- scale of the BigDecimal
value to be returned.BigDecimal
whose scale is the specified value, and
whose unscaled value is determined by multiplying or dividing
this BigDecimal
's unscaled value by the appropriate
power of ten to maintain its overall value.ArithmeticException
- if the specified scaling operation would
require rounding.setScale(int, int)
,
setScale(int, RoundingMode)
public BigDecimal movePointLeft(int n)
BigDecimal
which is equivalent to this one
with the decimal point moved n
places to the left. If
n
is non-negative, the call merely adds n
to
the scale. If n
is negative, the call is equivalent
to movePointRight(-n)
. The BigDecimal
returned by this call has value (this ×
10-n) and scale max(this.scale()+n,
0)
.n
- number of places to move the decimal point to the left.BigDecimal
which is equivalent to this one with the
decimal point moved n
places to the left.ArithmeticException
- if scale overflows.public BigDecimal movePointRight(int n)
BigDecimal
which is equivalent to this one
with the decimal point moved n
places to the right.
If n
is non-negative, the call merely subtracts
n
from the scale. If n
is negative, the call
is equivalent to movePointLeft(-n)
. The
BigDecimal
returned by this call has value (this
× 10n) and scale max(this.scale()-n,
0)
.n
- number of places to move the decimal point to the right.BigDecimal
which is equivalent to this one
with the decimal point moved n
places to the right.ArithmeticException
- if scale overflows.public BigDecimal scaleByPowerOfTen(int n)
this
* 10n). The scale of
the result is (this.scale() - n)
.n
- the exponent power of ten to scale bythis
* 10n)ArithmeticException
- if the scale would be
outside the range of a 32-bit integer.public BigDecimal stripTrailingZeros()
BigDecimal
which is numerically equal to
this one but with any trailing zeros removed from the
representation. For example, stripping the trailing zeros from
the BigDecimal
value 600.0
, which has
[BigInteger
, scale
] components equals to
[6000, 1], yields 6E2
with [BigInteger
,
scale
] components equals to [6, -2]. If
this BigDecimal is numerically equal to zero, then
BigDecimal.ZERO
is returned.BigDecimal
with any
trailing zeros removed.public int compareTo(BigDecimal val)
BigDecimal
with the specified
BigDecimal
. Two BigDecimal
objects that are
equal in value but have a different scale (like 2.0 and 2.00)
are considered equal by this method. This method is provided
in preference to individual methods for each of the six boolean
comparison operators (<, ==,
>, >=, !=, <=). The
suggested idiom for performing these comparisons is:
(x.compareTo(y)
<op> 0)
, where
<op> is one of the six comparison operators.compareTo
in interface Comparable<BigDecimal>
val
- BigDecimal
to which this BigDecimal
is
to be compared.BigDecimal
is numerically
less than, equal to, or greater than val
.public boolean equals(Object x)
BigDecimal
with the specified
Object
for equality. Unlike compareTo
, this method considers two
BigDecimal
objects equal only if they are equal in
value and scale (thus 2.0 is not equal to 2.00 when compared by
this method).equals
in class Object
x
- Object
to which this BigDecimal
is
to be compared.true
if and only if the specified Object
is a
BigDecimal
whose value and scale are equal to this
BigDecimal
's.compareTo(java.math.BigDecimal)
,
hashCode()
public BigDecimal min(BigDecimal val)
BigDecimal
and
val
.val
- value with which the minimum is to be computed.BigDecimal
whose value is the lesser of this
BigDecimal
and val
. If they are equal,
as defined by the compareTo
method, this
is returned.compareTo(java.math.BigDecimal)
public BigDecimal max(BigDecimal val)
BigDecimal
and val
.val
- value with which the maximum is to be computed.BigDecimal
whose value is the greater of this
BigDecimal
and val
. If they are equal,
as defined by the compareTo
method, this
is returned.compareTo(java.math.BigDecimal)
public int hashCode()
BigDecimal
. Note that
two BigDecimal
objects that are numerically equal but
differ in scale (like 2.0 and 2.00) will generally not
have the same hash code.hashCode
in class Object
BigDecimal
.equals(Object)
public String toString()
BigDecimal
,
using scientific notation if an exponent is needed.
A standard canonical string form of the BigDecimal
is created as though by the following steps: first, the
absolute value of the unscaled value of the BigDecimal
is converted to a string in base ten using the characters
'0'
through '9'
with no leading zeros (except
if its value is zero, in which case a single '0'
character is used).
Next, an adjusted exponent is calculated; this is the
negated scale, plus the number of characters in the converted
unscaled value, less one. That is,
-scale+(ulength-1)
, where ulength
is the
length of the absolute value of the unscaled value in decimal
digits (its precision).
If the scale is greater than or equal to zero and the
adjusted exponent is greater than or equal to -6
, the
number will be converted to a character form without using
exponential notation. In this case, if the scale is zero then
no decimal point is added and if the scale is positive a
decimal point will be inserted with the scale specifying the
number of characters to the right of the decimal point.
'0'
characters are added to the left of the converted
unscaled value as necessary. If no character precedes the
decimal point after this insertion then a conventional
'0'
character is prefixed.
Otherwise (that is, if the scale is negative, or the
adjusted exponent is less than -6
), the number will be
converted to a character form using exponential notation. In
this case, if the converted BigInteger
has more than
one digit a decimal point is inserted after the first digit.
An exponent in character form is then suffixed to the converted
unscaled value (perhaps with inserted decimal point); this
comprises the letter 'E'
followed immediately by the
adjusted exponent converted to a character form. The latter is
in base ten, using the characters '0'
through
'9'
with no leading zeros, and is always prefixed by a
sign character '-'
('\u002D') if the
adjusted exponent is negative, '+'
('\u002B') otherwise).
Finally, the entire string is prefixed by a minus sign
character '-'
('\u002D') if the unscaled
value is less than zero. No sign character is prefixed if the
unscaled value is zero or positive.
Examples:
For each representation [unscaled value, scale] on the left, the resulting string is shown on the right.
[123,0] "123" [-123,0] "-123" [123,-1] "1.23E+3" [123,-3] "1.23E+5" [123,1] "12.3" [123,5] "0.00123" [123,10] "1.23E-8" [-123,12] "-1.23E-10"Notes:
BigDecimal
values and the result of this conversion.
That is, every distinguishable BigDecimal
value
(unscaled value and scale) has a unique string representation
as a result of using toString
. If that string
representation is converted back to a BigDecimal
using
the BigDecimal(String)
constructor, then the original
value will be recovered.
NumberFormat
class and its subclasses.
toEngineeringString()
method may be used for
presenting numbers with exponents in engineering notation, and the
setScale
method may be used for
rounding a BigDecimal
so it has a known number of digits after
the decimal point.
Character.forDigit
is used.
toString
in class Object
BigDecimal
.Character.forDigit(int, int)
,
BigDecimal(java.lang.String)
public String toEngineeringString()
BigDecimal
,
using engineering notation if an exponent is needed.
Returns a string that represents the BigDecimal
as
described in the toString()
method, except that if
exponential notation is used, the power of ten is adjusted to
be a multiple of three (engineering notation) such that the
integer part of nonzero values will be in the range 1 through
999. If exponential notation is used for zero values, a
decimal point and one or two fractional zero digits are used so
that the scale of the zero value is preserved. Note that
unlike the output of toString()
, the output of this
method is not guaranteed to recover the same [integer,
scale] pair of this BigDecimal
if the output string is
converting back to a BigDecimal
using the string constructor. The result of this method meets
the weaker constraint of always producing a numerically equal
result from applying the string constructor to the method's output.
BigDecimal
, using
engineering notation if an exponent is needed.public String toPlainString()
BigDecimal
without an exponent field. For values with a positive scale,
the number of digits to the right of the decimal point is used
to indicate scale. For values with a zero or negative scale,
the resulting string is generated as if the value were
converted to a numerically equal value with zero scale and as
if all the trailing zeros of the zero scale value were present
in the result.
The entire string is prefixed by a minus sign character '-'
('\u002D') if the unscaled value is less than
zero. No sign character is prefixed if the unscaled value is
zero or positive.
Note that if the result of this method is passed to the
string constructor, only the
numerical value of this BigDecimal
will necessarily be
recovered; the representation of the new BigDecimal
may have a different scale. In particular, if this
BigDecimal
has a negative scale, the string resulting
from this method will have a scale of zero when processed by
the string constructor.
(This method behaves analogously to the toString
method in 1.4 and earlier releases.)BigDecimal
without an exponent field.toString()
,
toEngineeringString()
public BigInteger toBigInteger()
BigDecimal
to a BigInteger
.
This conversion is analogous to the
narrowing primitive conversion from double
to
long
as defined in section 5.1.3 of
The Java™ Language Specification:
any fractional part of this
BigDecimal
will be discarded. Note that this
conversion can lose information about the precision of the
BigDecimal
value.
To have an exception thrown if the conversion is inexact (in
other words if a nonzero fractional part is discarded), use the
toBigIntegerExact()
method.
BigDecimal
converted to a BigInteger
.public BigInteger toBigIntegerExact()
BigDecimal
to a BigInteger
,
checking for lost information. An exception is thrown if this
BigDecimal
has a nonzero fractional part.BigDecimal
converted to a BigInteger
.ArithmeticException
- if this
has a nonzero
fractional part.public long longValue()
BigDecimal
to a long
.
This conversion is analogous to the
narrowing primitive conversion from double
to
short
as defined in section 5.1.3 of
The Java™ Language Specification:
any fractional part of this
BigDecimal
will be discarded, and if the resulting
"BigInteger
" is too big to fit in a
long
, only the low-order 64 bits are returned.
Note that this conversion can lose information about the
overall magnitude and precision of this BigDecimal
value as well
as return a result with the opposite sign.public long longValueExact()
BigDecimal
to a long
, checking
for lost information. If this BigDecimal
has a
nonzero fractional part or is out of the possible range for a
long
result then an ArithmeticException
is
thrown.BigDecimal
converted to a long
.ArithmeticException
- if this
has a nonzero
fractional part, or will not fit in a long
.public int intValue()
BigDecimal
to an int
.
This conversion is analogous to the
narrowing primitive conversion from double
to
short
as defined in section 5.1.3 of
The Java™ Language Specification:
any fractional part of this
BigDecimal
will be discarded, and if the resulting
"BigInteger
" is too big to fit in an
int
, only the low-order 32 bits are returned.
Note that this conversion can lose information about the
overall magnitude and precision of this BigDecimal
value as well as return a result with the opposite sign.public int intValueExact()
BigDecimal
to an int
, checking
for lost information. If this BigDecimal
has a
nonzero fractional part or is out of the possible range for an
int
result then an ArithmeticException
is
thrown.BigDecimal
converted to an int
.ArithmeticException
- if this
has a nonzero
fractional part, or will not fit in an int
.public short shortValueExact()
BigDecimal
to a short
, checking
for lost information. If this BigDecimal
has a
nonzero fractional part or is out of the possible range for a
short
result then an ArithmeticException
is
thrown.BigDecimal
converted to a short
.ArithmeticException
- if this
has a nonzero
fractional part, or will not fit in a short
.public byte byteValueExact()
BigDecimal
to a byte
, checking
for lost information. If this BigDecimal
has a
nonzero fractional part or is out of the possible range for a
byte
result then an ArithmeticException
is
thrown.BigDecimal
converted to a byte
.ArithmeticException
- if this
has a nonzero
fractional part, or will not fit in a byte
.public float floatValue()
BigDecimal
to a float
.
This conversion is similar to the
narrowing primitive conversion from double
to
float
as defined in section 5.1.3 of
The Java™ Language Specification:
if this BigDecimal
has too great a
magnitude to represent as a float
, it will be
converted to Float.NEGATIVE_INFINITY
or Float.POSITIVE_INFINITY
as appropriate. Note that even when
the return value is finite, this conversion can lose
information about the precision of the BigDecimal
value.floatValue
in class Number
BigDecimal
converted to a float
.public double doubleValue()
BigDecimal
to a double
.
This conversion is similar to the
narrowing primitive conversion from double
to
float
as defined in section 5.1.3 of
The Java™ Language Specification:
if this BigDecimal
has too great a
magnitude represent as a double
, it will be
converted to Double.NEGATIVE_INFINITY
or Double.POSITIVE_INFINITY
as appropriate. Note that even when
the return value is finite, this conversion can lose
information about the precision of the BigDecimal
value.doubleValue
in class Number
BigDecimal
converted to a double
.public BigDecimal ulp()
BigDecimal
. An ulp of a nonzero BigDecimal
value is the positive distance between this value and the
BigDecimal
value next larger in magnitude with the
same number of digits. An ulp of a zero value is numerically
equal to 1 with the scale of this
. The result is
stored with the same scale as this
so the result
for zero and nonzero values is equal to [1,
this.scale()]
.this
Dracula Javadoc Sample, Made with Allan Im.


Adding a New Agent¶
Coach’s modularity makes adding an agent a simple and clean task. We suggest using the following Jupyter notebook tutorial to ramp up on this process. In general, it involves the following steps:
Implement your algorithm in a new file. The agent can inherit base classes such as ValueOptimizationAgent or ActorCriticAgent, or the more generic Agent base class.
Note
ValueOptimizationAgent, PolicyOptimizationAgent and Agent are abstract classes.
learn_from_batch()
should be overriden with the desired behavior for the algorithm being implemented. If deciding to inherit from Agent, alsochoose_action()
should be overriden.def learn_from_batch(self, batch) -> Tuple[float, List, List]: """ Given a batch of transitions, calculates their target values and updates the network. :param batch: A list of transitions :return: The total loss of the training, the loss per head and the unclipped gradients """ def choose_action(self, curr_state): """ choose an action to act with in the current episode being played. Different behavior might be exhibited when training or testing. :param curr_state: the current state to act upon. :return: chosen action, some action value describing the action (q-value, probability, etc) """
Implement your agent’s specific network head, if needed, at the implementation for the framework of your choice. For example architectures/neon_components/heads.py. The head will inherit the generic base class Head. A new output type should be added to configurations.py, and a mapping between the new head and output type should be defined in the get_output_head() function at architectures/neon_components/general_network.py
Define a new parameters class that inherits AgentParameters. The parameters class defines all the hyperparameters for the agent, and is initialized with 4 main components:
algorithm: A class inheriting AlgorithmParameters which defines any algorithm specific parameters
exploration: A class inheriting ExplorationParameters which defines the exploration policy parameters. There are several common exploration policies built-in which you can use, and are defined under the exploration sub directory. You can also define your own custom exploration policy.
memory: A class inheriting MemoryParameters which defined the memory parameters. There are several common memory types built-in which you can use, and are defined under the memories sub directory. You can also define your own custom memory.
networks: A dictionary defining all the networks that will be used by the agent. The keys of the dictionary define the network name and will be used to access each network through the agent class. The dictionary values are a class inheriting NetworkParameters, which define the network structure and parameters.
Additionally, set the path property to return the path to your agent class in the following format:
<path to python module>:<name of agent class>
For example,
class RainbowAgentParameters(AgentParameters): def __init__(self): super().__init__(algorithm=RainbowAlgorithmParameters(), exploration=RainbowExplorationParameters(), memory=RainbowMemoryParameters(), networks={"main": RainbowNetworkParameters()}) @property def path(self): return 'rainbow.rainbow_agent:RainbowAgent'
(Optional) Define a preset using the new agent type with a given environment, and the hyper-parameters that should be used for training on that environment.


Help Hank complete his collection of rocks minerals.
After having been shot by the cartel, Hank is recovering at home. Helped by the sweet and understanding Marie.
From his bed, he is bidding on rocks minerals to complete his collection, which is tricky: with the health care and physical therapy bills, he cannot go over his budget.
Help him get them all without spending more than he can afford, by clicking on a rock mineral to purchase as many as he can within the allocated allowance.
$
$
Wins:
Losses:
- You're ordering a new rock?
- I'm bidding on a new mineral.
- It's a nice one.
- What?
- It's pretty.
- I need the thing.
- Okay. Numero uno?
- Dos.
- Okay. Those… Those pretty little crystals. I like that.
- Okay.
- You okay?
- Fine.
- Can't you sleep?
- Actually, yes, Marie. This is me sleeping. What's it look like?
- Looks like you're looking at a rock at 2:24 in the morning.
- This is not a rock. This is a mineral, for, like, the tenth time.
- Okay. Got it.
- Blue corundum, to be precise.
- Blue corundum. Well, it's very pretty.
- It's encrusted with igneous biotite in a mica schist. Would you like some more detail Because I can give it to you.
- Hank.
- Found in the Central Cordillera of Irian Jaya. Blue corundum.
- I'm just saying it's 2 in the morning. I'm just asking if maybe…
- You know, when last I counted, Marie, there were four bedrooms in this house.
 We're going to get things organized.
- Yeah, it'll be about 10 minutes.
- You have a rock collection?
- It's a mineral collection. Uh, just a little something I… You guys want to see it? Want to see it?
- Sure. Let's go see it.
- Oh, hey, let me.
- Hey, it's all right. I got it. Come on, guys, it's down the hall here.
- Now that one there, that's Rhodonite, okay? It's manganese inosilicate.
- Cool. What… What makes it be all pink like that?
- Well, that's the manganese part, okay? It… It oxidizes, you know, like rust.
- Exactly. Manganese can have an oxidation state of between -3 and +7, which takes it through a range of colors… Purple, green, blue. But its most stable state is +2, which is usually pale pink. So…
- So Exactly.
Anyway, you, uh, you get the idea. - Yeah, it's, uh, interesting. Interesting stuff, that.
- Marie, is that my minerals?
- Yes, Hank.
- How many boxes? I don't know... Three, four, a hundred, a million. I don't know.
- Did you check them for damage?
- Oh, my God. They're rocks, Hank.
- No, they're minerals. Jesus, Marie, I got some geodes coming that are very delicate, all right? And I will not accept any boxes that have damage. Those delivery jackoffs, I'm telling you...
Just... Honey, would you check? Just check, please?


{% extends "layout.html" %} {% block page_title %} External link {% endblock %} {% block content %} {{ macro.breadcrumb() }} External link What is it? An external link. A link to a webpage that is not on GOV.UK screenshot Accessibility success criteria to do Test Cases 1 - GOV.UK Elements {% endblock %}
An external link. A link to a webpage that is not on GOV.UK
to do


The STICKY feature of this project is written using the position properties in CSS3.
It can put everywhere you like. When it touched the top of your screen, it will "stick" on it.
Watch the navbar. It will stop when it touch the top.


Long String Viewer
The long string viewer allows you to see strings that are too long to be viewed at the current column width.
Show Long String Viewer
By default, the viewer is on. To use it, simply left click on the cell you want to examine and a viewing window will display the string. To disable it, uncheck the Show Long String Viewer option.
Hide Automatically
By default, the viewing window will close automatically when your cursor leaves the cell that contains the string you are viewing. To turn off this behavior, uncheck the Hide Automatically option.
Long String Viewer Width
The value entered here gives the maximum number of characters that will be displayed on a line of the long string viewer. If more characters are needed, the string will be wrapped in a box of the given width. If fewer are needed the size of the viewer window will be adjusted downward to fit.
Maximum Length Displayed
This is the maximum string width that will be displayed in the long string viewer. Note that the maximum length of a string in Stat/Transfer is 32767 characters.
Variable Info Viewer
If you click on the variable name at the top of the grid, a Variable Info Viewer box will open up that will show you the variable name, its type and, if available, its label.
Show Variable Info Viewer
The Variable Info Viewer box is on by default. You can turn off this feature by unchecking the box.
Hide Automatically
By default, the viewing window will close automatically when your cursor leave the cell that contains the variable you are viewing. To turn off this behavior, uncheck the Hide Automatically option.
Autosize Column Names
The columns in the data viewer are sized to accommodate the width of the data. By checking this box, you can have the columns sized to accommodate the variable names.
Data Viewer Font
You can use this option to control the font that is used in the data viewer. Note that if you are displaying international character sets, you should choose a Unicode font, or at the very least a font that is capable of displaying the characters that you present in your data.


Tone's Event classes (Tone.ToneEvent,
Tone.Loop,
Tone.Part and
Tone.Sequence)
simplify scheduling events along the Transport. Each class abstracts away calls to
Transport.schedule or
scheduleRepeat
and lets you create precise, rhythmic events which are startable, stoppable and loopable.
(note that ToneEvent was called Event before Tone.js 14.x)


Unit 2, Week 6 Cultural Blogpost
Stereotype Threat
Thursday February 5, 2015
In our week 6 cultural blog post I want to examine my experiences with stereotype threat and look at how to to address stereotype threat in the most comprehensive way possible. Stereotype threat is the risk of conforming a negative stereotype of a social group someone represents. I am part of a few groups that are immediately clear: young, male, Indian American, new to software development. However I want to inspect another group that isn't immediately clear, a business failure. I have started and legitimately tried in more business ideas than I can remember. I do not view failure with a salty taste, I know that it is a legitimate function for learning. I am very glad I have tried my ideas and I will continue to get better at implementing them.
The stereotype threat of being a business failure is not what you may expect. The stereotype threat is to be the lone wolf no matter what. The threat is continuing to try on my own even when greater resources and tools exist elsewhere for me to learn. I feel that threat constantly within myself. I feel like I should swim against the current no matter what direction the river flows. I should avoid working at a large company and go for gold on my own ideas and knowledge base. This is hard to deal with and I feel the expectation when I look at many business minds that failed but went on to be ultimately successful.
I certainly feel this threat within myself. I feel torn between doing what is prescribed and what I discover. I feel challenged to do anything as a mandate, including and especially assignments from DBC. I feel challenged to view any formal source of learning as an opportunity to grow rather than an institution I need to refute. This prevents me from embracing DBC sometimes and doing our assignments on time.
A difference between my stereotype threat mentioned above and most of the ones we are familiar with is that being a business failure is a choice I made personally and, especially here in the Valley, it is not viewed as a particularly bad category to be in. More familiar stereotype threats are social pressures placed on our attributes and descriptions we had no control over. Statuses like race, age and gender identification all have stereotype threats and perhaps have their own unique stereotypes in the technology field we are entering.
If I observe a stereotype threat I will definitely keep it in mind and try to approach the subject with the individual in mind at a later time. I believe the most optimum way to handle someone lowering their expectations of themselves due to stereotype would be to speak with them in private. If I am able to create a safe space and communicate openly with someone, hopefully they would feel comfortable speaking about pressures they feel towards lower expectations they place on themselves. I believe this would best be done in a one on one environment. Hopefully in that space the person would feel empowered to talk about how they feel and where they heard they couldn't do as much because of their stereotype. Hopefully through good conversation and good experience with success, they can start to hold themselves accountable to any standard they want.
Cultivating an environment that does not cater to stereotype threats is not as easy as it sounds. While active choices like letting everyone know they are valued and letting everyone know they are capable of accomplishing tasks sounds nice, it only addresses part of a concern. I would argue for the most part environments are consequences of mostly passive choices that come together to affect stereotype threats. If we have an environment of all males and welcome females with open arms saying "everyone can code," are we sending that message through our hiring actions? If we have an environment that emphasizes late nights in the office, pounding energy drinks and team nights out at clubs and encourage anyone to join our team are we really being fair to those with families, are pregnant or want to build families? Those types of environments actually contribute to making selected classes not feel welcome and not feel capable.
Stereotype threats are not simply addressed through positive statements. Any individual needs to feel actually valued and feel like the workspace they are in has a high standard of them and the workspace they create in their head has a high standard as well. It is not easy to help people overcome these challenges, but most of the most important obstacles we face are not easy to overcome. It is in the benefit of everyone involved that people do not feel like they are capable of less and therefore do less. I hope to overcome my own stereotype threats some how and I definitely hope to help individuals and the environments I am a part of avoid stereotype threats in the future.


Provides functions for the creation, evaluation and test of decision models based in Multi Attribute Utility Theory (MAUT). Can process and evaluate local risk aversion utilities for a set of indexes, compute utilities and weights for the whole decision tree defining the decision model and simulate weights employing Dirichlet distributions under addition constraints in weights.
| Version: | 0.1.2 |
| Depends: | R (≥ 3.0) |
| Imports: | data.table, gtools, stringr, igraph, RColorBrewer, ggplot2, Rdpack |
| Suggests: | knitr, rmarkdown |
| Published: | 2018-01-17 |
| Author: | Felipe Aguirre [ctb], Julio Andrade [ctb], Pedro Guarderas [aut, cre], Daniel Lagos [ctb], Andrés Lopez [ctb], Nelson Recalde [ctb], Edison Salazar [ctb] |
| Maintainer: | Pedro Guarderas <pedro.felipe.guarderas at gmail.com> |
| License: | LGPL-3 |
| URL: | https://github.com/pedroguarderas/mau |
| NeedsCompilation: | no |
| Materials: | README NEWS |
| CRAN checks: | mau results |
| Reference manual: | mau.pdf |
| Vignettes: |
Running a MAUT Model |
| Package source: | mau_0.1.2.tar.gz |
| Windows binaries: | r-devel: mau_0.1.2.zip, r-release: mau_0.1.2.zip, r-oldrel: mau_0.1.2.zip |
| OS X binaries: | r-release: mau_0.1.2.tgz, r-oldrel: mau_0.1.2.tgz |
| Old sources: | mau archive |
Please use the canonical form https://CRAN.R-project.org/package=mau to link to this page.


Insert an image URL and payload, click 'Embed!', right-click -> save as, and upload the image below to extract the payload.
Source Image:
Payload:
Embed!
Upload Image:
Detected payload:


Databases v1¶
Setup¶
Rackspace setup¶
The first step is to pass in your credentials and set up a client. For Rackspace users, you will need your username and API key:
use OpenCloud\Rackspace;
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
'username' => '{username}',
'apiKey' => '{apiKey}',
));
OpenStack setup¶
If you’re an OpenStack user, you will also need to prove a few other configuration parameters:
$client = new OpenCloud\OpenStack('{keystoneUrl}', array(
'username' => '{username}',
'password' => '{apiKey}',
'tenantId' => '{tenantId}',
));
Databases service¶
Now to instantiate the Databases service:
$service = $client->databaseService('{catalogName}', '{region}', '{urlType}');
- {catalogName} is the name of the service as it appears in the service catalog. OpenStack users must set this value. For Rackspace users, a default will be provided if you pass in null.
- {region} is the region the service will operate in. For Rackspace users, you can select one of the following from the supported regions page.
- {urlType} is the type of URL to use, depending on which endpoints your catalog provides. If omitted, it will default to the public network.
Operations¶
Glossary¶
- configuration group
- A configuration group is a collection of key/value pairs which configure a database instance. Some directives are capable of being applied dynamically, while other directives require a server restart to take effect. The configuration group can be applied to an instance at creation or applied to an existing instance to modify the behavior of the running datastore on the instance.
- flavor
- A flavor is an available hardware configuration for a database instance. Each flavor has a unique combination of memory capacity and priority for CPU time.
- instance
- A database instance is an isolated MySQL instance in a single tenant environment on a shared physical host machine. Also referred to as instance.
- database
- A database is a local MySQL database running on an instance.
- user
- A user is a local MySQL user that can access a database running on an instance.
- datastore
- The database engine running on your instance. Currently, there is support for MySQL 5.6, MySQL 5.1, Percona 5.6 and MariaDB 10.
- volume
- A volume is user-specified storage that contains the database engine data directory. Volumes are automatically provisioned on shared Internet Small Computer System Interface (iSCSI) storage area networks (SAN) that provide for increased performance, scalability, availability and manageability. Applications with high I/O demands are performance optimized and data is protected through both local and network RAID-10.


More Categories
All docs
Launch Simple Websites
Digital Assets Subscription
Tutorials & Courses
Hire a Freelancer
453 Posts
624 Posts
120 Posts
235 Posts
Make use of a qualified tutor to get the answer
Viewing 8 topics - 1 through 10 (of 342 total)
Support is Offline
Monday - Friday / 10am - 6pm (UTC +4) NewYork
10:30:15 PM


Storm 0.9.0 Released
We are pleased to announce that Storm 0.9.0 has been released and is available from the downloads page. This release represents an important milestone in the evolution of Storm.
While a number of new features have been added, a key focus area for this release has been stability-related fixes. Though many users are successfully running work-in-progress builds for Storm 0.9.x in production, this release represents the most stable version to-date, and is highly recommended for everyone, especially users of 0.8.x versions.
Netty Transport
The first hightlight of this release is the new Netty Transport contributed by Yahoo! Engineering. Storm’s core network transport mechanism is now plugable, and Storm now comes with two implementations: The original 0MQ transport, and a new Netty-based implementation.
In earlier versions, Storm relied solely on 0MQ for transport. Since 0MQ is a native library, it was highly platform-dependent and, at times, challenging to install properly. In addition, stability between versions varied widely between versions and only a relatively old 0MQ version (2.1.7) was certified to work with Storm.
The Netty transport offers a pure Java alternative that eliminates Storm’s dependency on native libraries. The Netty transport’s performance is up to twice as fast as 0MQ, and it will open the door for authorization and authentication between worker processes. For an in-depth performance comparison of the 0MQ and Netty transports, see this blog post by Storm contributor Bobby Evans.
To configure Storm to use the Netty transport simply add the following to your storm.yaml
configuration and adjust the values to best suit your use-case:
storm.messaging.transport: "backtype.storm.messaging.netty.Context"
storm.messaging.netty.server_worker_threads: 1
storm.messaging.netty.client_worker_threads: 1
storm.messaging.netty.buffer_size: 5242880
storm.messaging.netty.max_retries: 100
storm.messaging.netty.max_wait_ms: 1000
storm.messaging.netty.min_wait_ms: 100
You can also write your own transport implementation by implementing the backtype.storm.messaging.IContext
interface.
Log Viewer UI
Storm now includes a helpful new feature for debugging and monitoring topologies: The logviewer
daemon.
In earlier versions of Storm, viewing worker logs involved determining a worker’s location (host/port), typically through Storm UI, then ssh
ing to that host and tail
ing the corresponding worker log file. With the new log viewer. You can now easily access a specific worker’s log in a web browser by clicking on a worker’s port number right from Storm UI.
The logviewer
daemon runs as a separate process on Storm supervisor nodes. To enable the logviewer
run the following command (under supervision) on your cluster’s supervisor nodes:
$ storm logviewer
Improved Windows Support
In previous versions, running Storm on Microsoft Windows required installing third-party binaries (0MQ), modifying Storm’s source, and adding Windows-specific scripts. With the addition of the platform-independent Netty transport, as well as numerous enhancements to make Storm more platform-independent, running Storm on Windows is easier than ever.
Security Improvements
Security, Authentication, and Authorization have been and will continue to be important focus areas for upcoming features. Storm 0.9.0 introduces an API for pluggable tuple serialization and a blowfish encryption based implementation for encrypting tuple data for sensitive use cases.
API Compatibility and Upgrading
For most Storm topology developers, upgrading to 0.9.0 is simply a matter of updating the dependency. Storm’s core API has changed very little since the 0.8.2 release.
On the devops side, when upgrading to a new Storm release, it is safest to clear any existing state (Zookeeper, storm.local.dir
), prior to upgrading.
Logging Changes
Another important change in 0.9.0 has to do with logging. Storm has largely switched over to the slf4j API (backed by a logback logger implementation). Some Storm dependencies rely on the log4j API, so Storm currently depends on log4j-over-slf4j.
These changes have implications for existing topologies and topology components that use the log4j API.
In general, and when possible, Storm topologies and topology components should use the slf4j API for logging.
Thanks
Special thanks are due to all those who have contributed to Storm – whether through direct code contributions, documentation, bug reports, or helping other users on the mailing lists. Your efforts are much appreciated.
Changelog
- Update build configuration to force compatibility with Java 1.6
- Fixed a netty client issue where sleep times for reconnection could be negative (thanks brndnmtthws)
- Fixed an issue that would cause storm-netty unit tests to fail
- Added configuration to limit ShellBolt internal _pendingWrites queue length (thanks xiaokang)
- Fixed a a netty client issue where sleep times for reconnection could be negative (thanks brndnmtthws)
- Fixed a display issue with system stats in Storm UI (thanks d2r)
- Nimbus now does worker heartbeat timeout checks as soon as heartbeats are updated (thanks d2r)
- The logviewer now determines log file location by examining the logback configuration (thanks strongh)
- Allow tick tuples to work with the system bolt (thanks xumingming)
- Add default configuration values for the netty transport and the ability to configure the number of worker threads (thanks revans2)
- Added timeout to unit tests to prevent a situation where tests would hang indefinitely (thanks d2r)
- Fixed an issue in the system bolt where local mode would not be detected accurately (thanks miofthena)
- Fixed
storm jar
command to work properly when STORM_JAR_JVM_OPTS is not specified (thanks roadkill001) - All logging now done with slf4j
- Replaced log4j logging system with logback
- Logs are now limited to 1GB per worker (configurable via logging configuration file)
- Build upgraded to leiningen 2.0
- Revamped Trident spout interfaces to support more dynamic spouts, such as a spout who reads from a changing set of brokers
- How tuples are serialized is now pluggable (thanks anfeng)
- Added blowfish encryption based tuple serialization (thanks anfeng)
- Have storm fall back to installed storm.yaml (thanks revans2)
- Improve error message when Storm detects bundled storm.yaml to show the URL’s for offending resources (thanks revans2)
- Nimbus throws NotAliveException instead of FileNotFoundException from various query methods when topology is no longer alive (thanks revans2)
- Escape HTML and Javascript appropriately in Storm UI (thanks d2r)
- Storm’s Zookeeper client now uses bounded exponential backoff strategy on failures
- Automatically drain and log error stream of multilang subprocesses
- Append component name to thread name of running executors so that logs are easier to read
- Messaging system used for passing messages between workers is now pluggable (thanks anfeng)
- Netty implementation of messaging (thanks anfeng)
- Include topology id, worker port, and worker id in properties for worker processes, useful for logging (thanks d2r)
- Tick tuples can now be scheduled using floating point seconds (thanks tscurtu)
- Added log viewer daemon and links from UI to logviewers (thanks xiaokang)
- DRPC server childopts now configurable (thanks strongh)
- Default number of ackers to number of workers, instead of just one (thanks lyogavin)
- Validate that Storm configs are of proper types/format/structure (thanks d2r)
- FixedBatchSpout will now replay batches appropriately on batch failure (thanks ptgoetz)
- Can set JAR_JVM_OPTS env variable to add jvm options when calling ‘storm jar’ (thanks srmelody)
- Throw error if batch id for transaction is behind the batch id in the opaque value (thanks mrflip)
- Sort topologies by name in UI (thanks jaked)
- Added LoggingMetricsConsumer to log all metrics to a file, by default not enabled (thanks mrflip)
- Add prepare(Map conf) method to TopologyValidator (thanks ankitoshniwal)
- Bug fix: Supervisor provides full path to workers to logging config rather than relative path (thanks revans2)
- Bug fix: Call ReducerAggregator#init properly when used within persistentAggregate (thanks lorcan)
- Bug fix: Set component-specific configs correctly for Trident spouts


Two roads diverged in a wood, and I—I took the one less traveled by...
and that has made all the difference.
Your brain is better at remember concepts, and you can always use visual cues to trigger them. It’s easier to captivate an audience with a story because we’re all very familiar with that format.
This is a story about a dad and an ill son. Written, directed, animated, designed, and all the things you can think about by me — mQ; this has been the start for me in the film industry.
One of the original creators of Popcorn-Time, first released in 2014. It was (and still is), based on my library Peerflix,
which can stream any type of content. Even to SmartTV's, Xbox, PS, Chromecast and other PCS's.
The software gain fast media attention, putting us in a spot where we didn't wanted to be. Now it exists thanks
to our open-source policy. There's Popcorn everywhere! And I'm very proud for being a part of it.
This is one of my pet projects. A platform where you can sync all your content between all your devices and the cloud. This software will make you aware that words are everywhere; even in the deepest silence. They're all floating through the air. Textile will catch them and make those words avaible for your eyes, and fingertips.
Skylog is a 3D robot, which's always listening every public conversation. With artificial intelligence, it stores the best quotes sayed by living people in a transitory chat. Each world, a little log. Each time, a different sky.
Landing page for people to get to know the native software. Motion-technologies were used in this work. In my perception, I really liked the result. 2D & 3D.
«Time is relative. It can stretch and it can squeeze, but... it can't run backwards. Just can't. The only thing that can move across dimensions, like time, is gravity»
Playing around with Blender and Javascript to recreate exactly the Textile Logo in 3D. More updates on this soon.
Centro de Educación Personalizada
¿Hay o no un creador? ¿Dónde va la luz cuando se apaga? Cualquier afirmación o negación cuando se trata del universo, es interesante. CEP es un lugar donde profesores y alumnos se reunen a aprender matemáticas, química, física, y muchas asignaturas más. Es una esencial ayuda para el universitario e ingresante.
One day, not long from now, it was the mother's day. I didn't have any money to give her a present. Inert and crying in the dark, I decided to write a heart for her; which's always beating. I love you mom.
I won't spoil it for you. This Ludovico Einaudi's score touched my soul so many times; even more when I play it myself. This time, I wanted to make the computer «feel it» the same way. Una Mattina, in an autumn day. There are no leaves falling, the music stopped the wind.
Nature startles me. Storms might freak out a lot of people─even me. But I found them interesting. Watching plasmatic ray transforming their way to earth. The background lights for a moment, and in a fraction of that moment, thousands of celsius degrees blows into something comparable to a nuclear explosion.
What's falling if the sky is set on fire?
Earth is my favorite planet; but there's something about Saturn that keeps me tuned. It's spinning so fast you won't ever tell where's a crater. In all my ignorance, I wanted to recreate it using 3D Technologies.
A work in progress. Thanks Dalton, Thomsom, Rutherford, Bohr, Dirac, ..., for this. They finally found the hair in the egg so precisely that changed the world. And others amazing human beings who are continuing studying from the biggest thing, to the smallest; which is this: the Atom. And it's neutrons+protons, with electrons orbiting around.
Before graduating from highschool, I saw this bridge every single day. A small blink at 6am. A strong glance around 2pm. And a «I see you tomorrow» at 7/8/9 pm. For years. Lots of friends, stories and thoughts crossed my mind in & around there.
Sometimes I feel like I can't do something. Like I'm not good enough. And that's why I like words, quotes, dialogs, communication: because it keeps changing my mind. Over the years, my mind changed so much that I don't think I have a personality at all. People can inspire me in so many ways that I know I can be better everyday. So I can do it. This project is finished; based in what is now Skylog.


--- layout: post title: Shh, it is an update post! summary: There has been a great deal of stuff happening over the last few months and this is an update. oneliner: Updates on Family, Hockey and Ice Skating. excerpt: What is going on here? Brett suddenly posting again? Yes! I've been lazy far too long now, I blame a distinct lack of motivation and pressure of trying to think ... categories: - Family - Hockey - Skating tags: - Boston Red Sox - Braden - Brett - Martin Brodeur - Minnesota Wild - New Jersey Devils - Paul Martin - Pittsburgh Penguins - Pittsburgh Pirates - Vicki - Zach Parise - Zbynek Michalek - Zoltan status: publish type: post published: true meta: _edit_last: '2' if_slider_image: '' slider_hidetitle: 'on' slider_custom_thumb: '' ---
What is going on here? Brett suddenly posting again? Yes! I've been lazy far too long now, I blame a distinct lack of motivation and pressure of trying to think of a new subject everyday. To me that smacks of a lack of commitment more than anything but I'll stick with my lazy excuse.
So the Devils made the Stanley Cup playoffs, they lost unfortunately, I would have loved to see them win, and given Parise's move to Minnesota it would have been a great ending to his Devils career. I also think that Brodeur would have retired if they won the cup, mind you I am happy to see both him and Johan back in the line up for next year.
I'm still a little shocked that Staal decided that he wanted to move, I can't blame him when looking at it from a perspective of the number of top line players the Pens have and of course the chance to play with his brother and all, but come on I really liked the dynamics of the Pens last season. Mind you I cannot wait for the new season to see just how they go, mind you I still think they should have traded Martin rather than Michalek, but who am I?
The Red Sox have been playing luke warm, more colder than hot. The Pirates on the other hand have been playing amazingly, it must be the awesomeness of Zoltan!
We've been doing pretty much the same around here, ice skating, ice hockey and all. Both Vicki and Braden have celebrated their birthdays in the last week. Vicki was sick for hers which meant we didn't do a great deal, but Braden and I still took her out to dinner to celebrate. Braden spent the day at the ice rink,no party, just a nice cake amongst friends and family, he was quite chuffed when he got to kiss Steph (his 'older' girlfriend) on the cheek.


| Attribute |
Public UNKNOWN_TYPE
|
Details:
| Alias: |
|
| Initial: |
|
| Stereotype: |
<<enum>> |
| Ordered: |
|
| Range: |
|
| Transient: |
False |
| Derived: |
False |
| IsID: |
False |
|
Public NONE
|
Details:
| Alias: |
|
| Initial: |
|
| Stereotype: |
<<enum>> |
| Ordered: |
|
| Range: |
|
| Transient: |
False |
| Derived: |
False |
| IsID: |
False |
|
Public RAIN
|
Details:
| Alias: |
|
| Initial: |
|
| Stereotype: |
<<enum>> |
| Ordered: |
|
| Range: |
|
| Transient: |
False |
| Derived: |
False |
| IsID: |
False |
|
Public MIXED_RAIN_SNOW
|
Details:
| Alias: |
|
| Initial: |
|
| Stereotype: |
<<enum>> |
| Ordered: |
|
| Range: |
|
| Transient: |
False |
| Derived: |
False |
| IsID: |
False |
|
Public SNOW
|
Details:
| Alias: |
|
| Initial: |
|
| Stereotype: |
<<enum>> |
| Ordered: |
|
| Range: |
|
| Transient: |
False |
| Derived: |
False |
| IsID: |
False |
|
Public HAIL
|
Details:
| Alias: |
|
| Initial: |
|
| Stereotype: |
<<enum>> |
| Ordered: |
|
| Range: |
|
| Transient: |
False |
| Derived: |
False |
| IsID: |
False |
|


--- layout: card-page title: About image: "sunil2.png" ---
I am a Ph.D. candidate in the Department of Computer Science at the College of William & Mary. I am working under Dr. Adwait Nadkarni. My research interest include IoT security, analysis and enforcement of access control policies in smart home systems, software security, and machine learning.
I completed by B.Sc. in Computer Science and Information Technology from St. Xavier's College, Nepal.


{% extends 'layout.html' %} {% block body %}
Make your self a profile. It's easy and beautiful.
We have cheerfully built this system to ease your organization members profile, Please Feel free to contact for any new feature requests or help.