Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 56 additions & 56 deletions src/System.Private.CoreLib/src/System/Decimal.DecCalc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,38 @@ public partial struct Decimal
// Low level accessors used by a DecCalc and formatting
internal uint High
{
get { return hi; }
set { hi = value; }
get { return uhi; }
set { uhi = value; }
}

internal uint Low
{
get { return lo; }
set { lo = value; }
get { return ulo; }
set { ulo = value; }
}

internal uint Mid
{
get { return mid; }
set { mid = value; }
get { return umid; }
set { umid = value; }
}

internal bool Sign
{
get { return (flags & SignMask) != 0; }
set { flags = (flags & ~SignMask) | (value ? SignMask : 0); }
get { return (uflags & SignMask) != 0; }
set { uflags = (uflags & ~SignMask) | (value ? SignMask : 0); }
}

internal int Scale
{
get { return (int)((flags & ScaleMask) >> ScaleShift); }
set { flags = (flags & ~ScaleMask) | ((uint)value << ScaleShift); }
get { return (int)((uflags & ScaleMask) >> ScaleShift); }
set { uflags = (uflags & ~ScaleMask) | ((uint)value << ScaleShift); }
}

private ulong Low64
{
get { return ((ulong)mid << 32) | lo; }
set { mid = (uint)(value >> 32); lo = (uint)value; }
get { return ((ulong)umid << 32) | ulo; }
set { umid = (uint)(value >> 32); ulo = (uint)value; }
}

#region APIs need by number formatting.
Expand Down Expand Up @@ -1190,7 +1190,7 @@ private static void RoundUp(uint[] rgulQuo, ref int iScale)
//
private static Decimal Abs(Decimal d)
{
return new Decimal((int)d.lo, (int)d.mid, (int)d.hi, (int)(d.flags & ~SignMask));
return new Decimal(d.lo, d.mid, d.hi, (int)(d.uflags & ~SignMask));
}

/***
Expand Down Expand Up @@ -1219,9 +1219,9 @@ private static uint DecFixInt(ref Decimal input, ref Decimal result)

if (input.Scale > 0)
{
tmpNum[0] = input.lo;
tmpNum[1] = input.mid;
tmpNum[2] = input.hi;
tmpNum[0] = input.ulo;
tmpNum[1] = input.umid;
tmpNum[2] = input.uhi;
scale = input.Scale;
result.Sign = input.Sign;
remainder = 0;
Expand All @@ -1237,9 +1237,9 @@ private static uint DecFixInt(ref Decimal input, ref Decimal result)
scale -= MaxInt32Scale;
} while (scale > 0);

result.lo = tmpNum[0];
result.mid = tmpNum[1];
result.hi = tmpNum[2];
result.ulo = tmpNum[0];
result.umid = tmpNum[1];
result.uhi = tmpNum[2];
result.Scale = 0;

return remainder;
Expand All @@ -1255,7 +1255,7 @@ private static uint DecFixInt(ref Decimal input, ref Decimal result)
//**********************************************************************
internal static void VarCyFromDec(ref Decimal pdecIn, out long pcyOut)
{
if (!Decimal.IsValid(pdecIn.flags))
if (!Decimal.IsValid(pdecIn.uflags))
throw new OverflowException(SR.Overflow_Currency);

Split64 sdlTmp = default(Split64);
Expand Down Expand Up @@ -2388,9 +2388,9 @@ internal static void VarDecRound(ref Decimal input, int decimals, ref Decimal re
scale = input.Scale - decimals;
if (scale > 0)
{
tmpNum[0] = input.lo;
tmpNum[1] = input.mid;
tmpNum[2] = input.hi;
tmpNum[0] = input.ulo;
tmpNum[1] = input.umid;
tmpNum[2] = input.uhi;
result.Sign = input.Sign;
remainder = sticky = 0;

Expand All @@ -2416,9 +2416,9 @@ internal static void VarDecRound(ref Decimal input, int decimals, ref Decimal re
&& ++tmpNum[1] == 0)
++tmpNum[2];

result.lo = tmpNum[0];
result.mid = tmpNum[1];
result.hi = tmpNum[2];
result.ulo = tmpNum[0];
result.umid = tmpNum[1];
result.uhi = tmpNum[2];
result.Scale = decimals;
return;
}
Expand All @@ -2434,7 +2434,7 @@ internal static Decimal VarDecMod(ref Decimal d1, ref Decimal d2)
// OleAut doesn't provide a VarDecMod.

// In the operation x % y the sign of y does not matter. Result will have the sign of x.
d2.flags = (d2.flags & ~SignMask) | (d1.flags & SignMask);
d2.uflags = (d2.uflags & ~SignMask) | (d1.uflags & SignMask);


// This piece of code is to work around the fact that Dividing a decimal with 28 digits number by decimal which causes
Expand All @@ -2449,22 +2449,22 @@ internal static Decimal VarDecMod(ref Decimal d1, ref Decimal d2)
if (d1 == 0)
{
// The sign of D1 will be wrong here. Fall through so that we still get a DivideByZeroException
d1.flags = (d1.flags & ~SignMask) | (d2.flags & SignMask);
d1.uflags = (d1.uflags & ~SignMask) | (d2.uflags & SignMask);
}

// Formula: d1 - (RoundTowardsZero(d1 / d2) * d2)
Decimal dividedResult = Truncate(d1 / d2);
Decimal multipliedResult = dividedResult * d2;
Decimal result = d1 - multipliedResult;
// See if the result has crossed 0
if ((d1.flags & SignMask) != (result.flags & SignMask))
if ((d1.uflags & SignMask) != (result.uflags & SignMask))
{
if (NearNegativeZero <= result && result <= NearPositiveZero)
{
// Certain Remainder operations on decimals with 28 significant digits round
// to [+-]0.000000000000000000000000001m instead of [+-]0m during the intermediate calculations.
// 'zero' results just need their sign corrected.
result.flags = (result.flags & ~SignMask) | (d1.flags & SignMask);
result.uflags = (result.uflags & ~SignMask) | (d1.uflags & SignMask);
}
else
{
Expand All @@ -2487,17 +2487,17 @@ private static void InternalAddUInt32RawUnchecked(ref Decimal value, UInt32 i)
{
UInt32 v;
UInt32 sum;
v = value.lo;
v = value.ulo;
sum = v + i;
value.lo = sum;
value.ulo = sum;
if (sum < v || sum < i)
{
v = value.mid;
v = value.umid;
sum = v + 1;
value.mid = sum;
value.umid = sum;
if (sum < v || sum < 1)
{
value.hi = value.hi + 1;
value.uhi = value.uhi + 1;
}
}
}
Expand All @@ -2509,22 +2509,22 @@ private static UInt32 InternalDivRemUInt32(ref Decimal value, UInt32 divisor)
{
UInt32 remainder = 0;
UInt64 n;
if (value.hi != 0)
if (value.uhi != 0)
{
n = value.hi;
value.hi = (UInt32)(n / divisor);
n = value.uhi;
value.uhi = (UInt32)(n / divisor);
remainder = (UInt32)(n % divisor);
}
if (value.mid != 0 || remainder != 0)
if (value.umid != 0 || remainder != 0)
{
n = ((UInt64)remainder << 32) | value.mid;
value.mid = (UInt32)(n / divisor);
n = ((UInt64)remainder << 32) | value.umid;
value.umid = (UInt32)(n / divisor);
remainder = (UInt32)(n % divisor);
}
if (value.lo != 0 || remainder != 0)
if (value.ulo != 0 || remainder != 0)
{
n = ((UInt64)remainder << 32) | value.lo;
value.lo = (UInt32)(n / divisor);
n = ((UInt64)remainder << 32) | value.ulo;
value.ulo = (UInt32)(n / divisor);
remainder = (UInt32)(n % divisor);
}
return remainder;
Expand Down Expand Up @@ -2573,17 +2573,17 @@ private static uint D32DivMod1E9(uint hi32, ref uint lo32)
internal static uint DecDivMod1E9(ref Decimal value)
{
return D32DivMod1E9(D32DivMod1E9(D32DivMod1E9(0,
ref value.hi),
ref value.mid),
ref value.lo);
ref value.uhi),
ref value.umid),
ref value.ulo);
}

internal static void DecAddInt32(ref Decimal value, uint i)
{
if (D32AddCarry(ref value.lo, i))
if (D32AddCarry(ref value.ulo, i))
{
if (D32AddCarry(ref value.mid, 1))
D32AddCarry(ref value.hi, 1);
if (D32AddCarry(ref value.umid, 1))
D32AddCarry(ref value.uhi, 1);
}
}

Expand Down Expand Up @@ -2615,16 +2615,16 @@ private static void DecShiftLeft(ref Decimal value)

private static void DecAdd(ref Decimal value, Decimal d)
{
if (D32AddCarry(ref value.lo, d.Low))
if (D32AddCarry(ref value.ulo, d.Low))
{
if (D32AddCarry(ref value.mid, 1))
D32AddCarry(ref value.hi, 1);
if (D32AddCarry(ref value.umid, 1))
D32AddCarry(ref value.uhi, 1);
}

if (D32AddCarry(ref value.mid, d.Mid))
D32AddCarry(ref value.hi, 1);
if (D32AddCarry(ref value.umid, d.Mid))
D32AddCarry(ref value.uhi, 1);

D32AddCarry(ref value.hi, d.High);
D32AddCarry(ref value.uhi, d.High);
}

#endregion
Expand Down
Loading