@@ -222,8 +222,8 @@ Supported Classes
222222
223223Core Ruby classes that have representations in the BSON specification and
224224will have a ``to_bson`` method defined for them are: ``Object``, ``Array``,
225- ``FalseClass``, ``Float``, ``Hash``, ``Integer``, ``NilClass ``, ``Regexp ``,
226- ``String``, ``Symbol`` (deprecated), ``Time``, ``TrueClass``.
225+ ``FalseClass``, ``Float``, ``Hash``, ``Integer``, ``BigDecimal ``, ``NilClass ``,
226+ ``Regexp``, `` String``, ``Symbol`` (deprecated), ``Time``, ``TrueClass``.
227227
228228In addition to the core Ruby objects, BSON also provides some special types
229229specific to the specification:
@@ -523,6 +523,26 @@ decimal rounding with exact precision.
523523 d = BigDecimal(1.28, 3)
524524 BSON::Decimal128.new(d)
525525
526+ BSON::Decimal128 vs BigDecimal
527+ ``````````````````````````````
528+ The ``BigDecimal`` ``from_bson`` and ``to_bson`` methods use the same
529+ ``BSON::Decimal128`` methods under the hood. This leads to some limitations
530+ that are imposed on the ``BigDecimal`` values that can be serialized to BSON
531+ and those that can be deserialized from existing ``BSON::Decimal128`` BSON
532+ objects. This change was made because serializing ``BigDecimal`` instances as
533+ ``BSON::Decimal128`` instances allows for more flexibility in terms of querying
534+ and aggregation in MongoDB. The limitations imposed on ``BigDecimal`` are as
535+ follows:
536+
537+ - ``BSON::Decimal128`` has a limited range and precision, while ``BigDecimal``
538+ has no restrictions in terms of range and precision. ``BSON::Decimal128`` has
539+ a max value of approximately ``10^6145`` and a min value of approximately
540+ ``-10^6145``, and has a maximum of 34 bits of precision.
541+
542+ - ``BSON::Decimal128`` is able to accept signed ``NaN`` values, while
543+ ``BigDecimal`` is not. All signed ``NaN`` values that are deserialized into
544+ ``BigDecimal`` instances will be unsigned.
545+
526546``Symbol``
527547----------
528548
0 commit comments