diff options
author | Jan Kotas <jkotas@microsoft.com> | 2015-12-22 17:23:16 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2015-12-23 17:43:25 +0300 |
commit | 4fc65c794dddd082dd9a0390ccada101f9e81424 (patch) | |
tree | 34f8e34a658f75db663cd18a80cc25ed7f6e1ba8 /src/System.Private.CoreLib | |
parent | d1823e83d7335aa99b1cff887543a56c2b17aa78 (diff) |
Cleanup HResults from Decimal
Diffstat (limited to 'src/System.Private.CoreLib')
-rw-r--r-- | src/System.Private.CoreLib/src/System/Decimal.DecCalc.cs | 50 | ||||
-rw-r--r-- | src/System.Private.CoreLib/src/System/Decimal.cs | 28 |
2 files changed, 28 insertions, 50 deletions
diff --git a/src/System.Private.CoreLib/src/System/Decimal.DecCalc.cs b/src/System.Private.CoreLib/src/System/Decimal.DecCalc.cs index 030200548..10e02fe23 100644 --- a/src/System.Private.CoreLib/src/System/Decimal.DecCalc.cs +++ b/src/System.Private.CoreLib/src/System/Decimal.DecCalc.cs @@ -828,7 +828,7 @@ namespace System // DecAddSub adds or subtracts two decimal values. On return, d1 contains the result // of the operation. Passing in true for bSign means subtract and false means add. // - // Resturns true if we overflow otherwise false. + // Returns true if we overflow otherwise false. private static bool DecAddSub(ref Decimal d1, ref Decimal d2, bool bSign) { uint[] rgulNum = new uint[6]; @@ -1287,7 +1287,7 @@ namespace System //********************************************************************** // VarDecMul - Decimal Multiply //********************************************************************** - internal static int VarDecMul(ref Decimal pdecL, ref Decimal pdecR, out Decimal pdecRes) + internal static void VarDecMul(ref Decimal pdecL, ref Decimal pdecR, out Decimal pdecRes) { Split64 sdlTmp = new Split64(); Split64 sdlTmp2 = new Split64(); @@ -1317,7 +1317,7 @@ namespace System if (iScale > 19) { //DECIMAL_SETZERO(*pdecRes); - return 0; + return; } if (iScale > MaxInt32Scale) { @@ -1440,12 +1440,12 @@ namespace System { iHiProd--; if (iHiProd < 0) - return 0; + return; } iScale = ScaleResult(rgulProd, iHiProd, iScale); if (iScale == -1) - return __HResults.COR_E_OVERFLOW; + throw new OverflowException(SR.Overflow_Decimal); pdecRes.Low = rgulProd[0]; pdecRes.Mid = rgulProd[1]; @@ -1454,13 +1454,12 @@ namespace System pdecRes.Sign = pdecR.Sign ^ pdecL.Sign; pdecRes.Scale = (char)iScale; - return 0; } //********************************************************************** // VarDecFromR4 - Convert float to Decimal //********************************************************************** - internal static int VarDecFromR4(float input, out Decimal pdecOut) + internal static void VarDecFromR4(float input, out Decimal pdecOut) { int iExp; // number of bits to left of binary point int iPower; @@ -1478,10 +1477,10 @@ namespace System // iExp = (int)(GetExponent(input) - SNGBIAS); if (iExp < -94) - return 0; // result should be zeroed out + return; // result should be zeroed out if (iExp > 96) - return __HResults.COR_E_OVERFLOW; + throw new OverflowException(SR.Overflow_Decimal); // Round the input to a 7-digit integer. The R4 format has // only 7 digits of precision, and we want to keep garbage digits @@ -1529,7 +1528,7 @@ namespace System ulMant++; if (ulMant == 0) - return 0; // result should be zeroed out + return; // result should be zeroed out if (iPower < 0) { @@ -1553,7 +1552,7 @@ namespace System sdlHi.int64 = tmplong; if (sdlHi.High32 != 0) - return __HResults.COR_E_OVERFLOW; + throw new OverflowException(SR.Overflow_Decimal); } else { @@ -1607,13 +1606,13 @@ namespace System } pdecOut.Sign = input < 0; - return 0; } //********************************************************************** // VarDecFromR8 - Convert double to Decimal + // Returns true if we overflow otherwise false. //********************************************************************** - internal static int VarDecFromR8(double input, out Decimal pdecOut) + internal static void VarDecFromR8(double input, out Decimal pdecOut) { int iExp; // number of bits to left of binary point int iPower; // power-of-10 scale factor @@ -1632,10 +1631,10 @@ namespace System // iExp = (int)(GetExponent(input) - DBLBIAS); if (iExp < -94) - return 0; // result should be zeroed out + return; // result should be zeroed out if (iExp > 96) - return __HResults.COR_E_OVERFLOW; + throw new OverflowException(SR.Overflow_Decimal); dbl = input; if (dbl < 0) dbl *= -1; @@ -1684,7 +1683,7 @@ namespace System sdlMant.int64++; if (sdlMant.int64 == 0) - return 0; // result should be zeroed out + return; // result should be zeroed out if (iPower < 0) { @@ -1709,7 +1708,7 @@ namespace System sdlMant.int64 = tmpValue; if (sdlMant.High32 != 0) - return __HResults.COR_E_OVERFLOW; + throw new OverflowException(SR.Overflow_Decimal); } pdecOut.Low64 = sdlLo.int64; pdecOut.High = sdlMant.Low32; @@ -1769,28 +1768,20 @@ namespace System } pdecOut.Sign = input < 0; - - return 0; } //********************************************************************** // VarR4ToDec - Convert Decimal to float //********************************************************************** - internal static int VarR4FromDec(ref Decimal pdecIn, out float pfltOut) + internal static float VarR4FromDec(ref Decimal pdecIn) { - double dbl; - - // Can't overflow; no errors possible. - // - VarR8FromDec(ref pdecIn, out dbl); - pfltOut = (float)dbl; - return 0; + return (float)VarR8FromDec(ref pdecIn); } //********************************************************************** // VarR8ToDec - Convert Decimal to double //********************************************************************** - internal static int VarR8FromDec(ref Decimal pdecIn, out double pdblOut) + internal static double VarR8FromDec(ref Decimal pdecIn) { double dbl = ((double)pdecIn.Low64 + (double)pdecIn.High * ds2to64) / GetDoublePower10(pdecIn.Scale); @@ -1798,8 +1789,7 @@ namespace System if (pdecIn.Sign) dbl = -dbl; - pdblOut = dbl; - return 0; + return dbl; } // VarDecAdd divides two decimal values. On return, d1 contains the result diff --git a/src/System.Private.CoreLib/src/System/Decimal.cs b/src/System.Private.CoreLib/src/System/Decimal.cs index b1c76b574..16019540d 100644 --- a/src/System.Private.CoreLib/src/System/Decimal.cs +++ b/src/System.Private.CoreLib/src/System/Decimal.cs @@ -179,16 +179,14 @@ namespace System // public Decimal(float value) { - if (DecCalc.VarDecFromR4(value, out this) < 0) - throw new OverflowException(SR.Overflow_Decimal); + DecCalc.VarDecFromR4(value, out this); } // Constructs a Decimal from a double value. // public Decimal(double value) { - if (DecCalc.VarDecFromR8(value, out this) < 0) - throw new OverflowException(SR.Overflow_Decimal); + DecCalc.VarDecFromR8(value, out this); } // Constructs a Decimal from an integer array containing a binary @@ -363,8 +361,7 @@ namespace System // public unsafe override int GetHashCode() { - double dbl; - DecCalc.VarR8FromDec(ref this, out dbl); + double dbl = DecCalc.VarR8FromDec(ref this); if (dbl == 0.0) // Ensure 0 and -0 have the same hash code return 0; @@ -537,12 +534,9 @@ namespace System [System.Security.SecuritySafeCritical] // auto-generated public static Decimal Multiply(Decimal d1, Decimal d2) { - Decimal decRes = new Decimal(); - if (DecCalc.VarDecMul(ref d1, ref d2, out decRes) < 0) - throw new OverflowException(SR.Overflow_Decimal); - - d1 = decRes; - return d1; + Decimal decRes; + DecCalc.VarDecMul(ref d1, ref d2, out decRes); + return decRes; } // Returns the negated value of the given Decimal. If d is non-zero, @@ -669,10 +663,7 @@ namespace System // public static double ToDouble(Decimal d) { - double result = 0.0; - // Note: this can fail if the input is an invalid decimal, but for compatibility we should return 0 - DecCalc.VarR8FromDec(ref d, out result); - return result; + return DecCalc.VarR8FromDec(ref d); } // Converts a Decimal to an integer. The Decimal value is rounded towards @@ -783,10 +774,7 @@ namespace System // public static float ToSingle(Decimal d) { - float result = 0.0f; - // Note: this can fail if the input is an invalid decimal, but for compatibility we should return 0 - DecCalc.VarR4FromDec(ref d, out result); - return result; + return DecCalc.VarR4FromDec(ref d); } // Truncates a Decimal to an integer value. The Decimal argument is rounded |