Skip to content

Commit ef25738

Browse files
committed
JAVA-2343: Improve the Decimal128 Javadoc
Add links to relevant articles and specifications Document the conditions under which the bigDecimalValue method will throw an ArithmeticException Document the conditions under which factory methods and constructors with throw a NumberFormatException
1 parent c0c7f52 commit ef25738

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

bson/src/main/org/bson/types/Decimal128.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@
2626
import static java.util.Arrays.asList;
2727

2828
/**
29-
* A representation of a 128-bit decimal.
29+
* A binary integer decimal representation of a 128-bit decimal value, supporting 34 decimal digits of significand and an exponent range
30+
* of -6143 to +6144.
3031
*
3132
* @since 3.4
33+
* @see <a href="https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.rst">BSON Decimal128
34+
* specification</a>
35+
* @see <a href="https://en.wikipedia.org/wiki/Binary_Integer_Decimal">binary integer decimal</a>
36+
* @see <a href="https://en.wikipedia.org/wiki/Decimal128_floating-point_format">decimal128 floating-point format</a>
37+
* @see <a href="http://ieeexplore.ieee.org/document/4610935/">754-2008 - IEEE Standard for Floating-Point Arithmetic</a>
3238
*/
3339
public final class Decimal128 implements Serializable {
3440

@@ -96,6 +102,10 @@ public final class Decimal128 implements Serializable {
96102
*
97103
* @param value the Decimal128 value represented as a String
98104
* @return the Decimal128 value representing the given String
105+
* @throws NumberFormatException if the value is out of the Decimal128 range
106+
* @see
107+
* <a href="https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.rst#from-string-representation">
108+
* From-String Specification</a>
99109
*/
100110
public static Decimal128 parse(final String value) {
101111
String lowerCasedValue = value.toLowerCase();
@@ -140,6 +150,7 @@ public Decimal128(final long value) {
140150
* Constructs a Decimal128 value representing the given BigDecimal.
141151
*
142152
* @param value the Decimal128 value represented as a BigDecimal
153+
* @throws NumberFormatException if the value is out of the Decimal128 range
143154
*/
144155
public Decimal128(final BigDecimal value) {
145156
this(value, value.signum() == -1);
@@ -260,6 +271,8 @@ public long getLow() {
260271
* Gets a BigDecimal that is equivalent to this Decimal128.
261272
*
262273
* @return a BigDecimal that is equivalent to this Decimal128
274+
* @throws ArithmeticException if the Decimal128 value is NaN, Infinity, -Infinity, or -0, none of which can be represented as a
275+
* BigDecimal
263276
*/
264277
public BigDecimal bigDecimalValue() {
265278

@@ -364,7 +377,7 @@ public boolean isNaN() {
364377
/**
365378
* Returns true if the encoded representation of this instance is the same as the encoded representation of {@code o}.
366379
* <p>
367-
* One consiquence is that, whereas {@code Double.NaN != Double.NaN},
380+
* One consequence is that, whereas {@code Double.NaN != Double.NaN},
368381
* {@code new Decimal128("NaN").equals(new Decimal128("NaN")} returns true.
369382
* </p>
370383
* <p>
@@ -403,6 +416,13 @@ public int hashCode() {
403416
return result;
404417
}
405418

419+
/**
420+
* Returns the String representation of the Decimal128 value.
421+
*
422+
* @return the String representation
423+
* @see <a href="https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.rst#to-string-representation">
424+
* To-String Sprecification</a>
425+
*/
406426
@Override
407427
public String toString() {
408428
if (isNaN()) {

0 commit comments

Comments
 (0)