File tree Expand file tree Collapse file tree 2 files changed +11
-8
lines changed
src/MongoDB.Bson/ObjectModel
tests/MongoDB.Bson.Tests/Serialization/Options Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -739,16 +739,18 @@ public static byte ToByte(Decimal128 d)
739739 /// <returns>A <see cref="decimal"/> equivalent to <paramref name="d" />.</returns>
740740 public static decimal ToDecimal ( Decimal128 d )
741741 {
742- if ( d == Decimal128 . MaxValue )
743- {
744- return decimal . MaxValue ;
745- }
746- else if ( d == Decimal128 . MinValue )
747- {
748- return decimal . MinValue ;
749- }
750742 if ( Flags . IsFirstForm ( d . _highBits ) )
751743 {
744+ // fix for CSHARP-5792, make sure that Decimal128.MaxValue and MinValue are mapped back to
745+ // decimal.MaxValue and MinValue.
746+ if ( d == Decimal128 . MaxValue )
747+ {
748+ return decimal . MaxValue ;
749+ }
750+ if ( d == Decimal128 . MinValue )
751+ {
752+ return decimal . MinValue ;
753+ }
752754 if ( Decimal128 . Compare ( d , __minDecimalValue ) < 0 || Decimal128 . Compare ( d , __maxDecimalValue ) > 0 )
753755 {
754756 throw new OverflowException ( "Value is too large or too small to be converted to a Decimal." ) ;
Original file line number Diff line number Diff line change @@ -123,6 +123,7 @@ public void TestConversions()
123123 // general decimal <-> Decimal128 checks
124124 Assert . Equal ( 123.45m , converter . ToDecimal ( new Decimal128 ( 123.45m ) ) ) ;
125125 Assert . Equal ( - 123.45m , converter . ToDecimal ( new Decimal128 ( - 123.45m ) ) ) ;
126+
126127 // System.Decimal should be mapped to Decimal128.MaxValue and vice versa
127128 Assert . Equal ( Decimal128 . MaxValue , converter . ToDecimal128 ( decimal . MaxValue ) ) ;
128129 Assert . Equal ( Decimal128 . MinValue , converter . ToDecimal128 ( decimal . MinValue ) ) ;
You can’t perform that action at this time.
0 commit comments