Summary

Class:System.DecimalDecCalc
Assembly:System.Memory
File(s):C:\GitHub\corefx\src\System.Memory\src\System\Number\Decimal.DecCalc.cs
Covered lines:51
Uncovered lines:0
Coverable lines:51
Total lines:86
Line coverage:100%
Branch coverage:100%

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
D32DivMod1E9(...)10100100
DecDivMod1E9(...)10100100
DecAddInt32(...)34100100
D32AddCarry(...)20100100
DecMul10(...)10100100
DecShiftLeft(...)54100100
DecAdd(...)48100100

File(s)

C:\GitHub\corefx\src\System.Memory\src\System\Number\Decimal.DecCalc.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3// See the LICENSE file in the project root for more information.
 4
 5//
 6// This code is copied almost verbatim from the same-named file in CoreRT with mechanical changes to make it build outsi
 7//
 8
 9namespace System
 10{
 11    internal static class DecimalDecCalc
 12    {
 13        private static uint D32DivMod1E9(uint hi32, ref uint lo32)
 114        {
 115            ulong n = (ulong)hi32 << 32 | lo32;
 116            lo32 = (uint)(n / 1000000000);
 117            return (uint)(n % 1000000000);
 118        }
 19
 20        // Performs the equivalent of:
 21        //
 22        //    uint modulo = value % 1e9;
 23        //    value = value / 1e9;
 24        //    return modulo;
 25        //
 26        internal static uint DecDivMod1E9(ref MutableDecimal value)
 127        {
 128            return D32DivMod1E9(D32DivMod1E9(D32DivMod1E9(0, ref value.High), ref value.Mid), ref value.Low);
 129        }
 30
 31        internal static void DecAddInt32(ref MutableDecimal value, uint i)
 132        {
 133            if (D32AddCarry(ref value.Low, i))
 134            {
 135                if (D32AddCarry(ref value.Mid, 1))
 136                {
 137                    D32AddCarry(ref value.High, 1);
 138                }
 139            }
 140        }
 41
 42        private static bool D32AddCarry(ref uint value, uint i)
 143        {
 144            uint v = value;
 145            uint sum = v + i;
 146            value = sum;
 147            return (sum < v) || (sum < i);
 148        }
 49
 50        internal static void DecMul10(ref MutableDecimal value)
 151        {
 152            MutableDecimal d = value;
 153            DecShiftLeft(ref value);
 154            DecShiftLeft(ref value);
 155            DecAdd(ref value, d);
 156            DecShiftLeft(ref value);
 157        }
 58
 59        private static void DecShiftLeft(ref MutableDecimal value)
 160        {
 161            uint c0 = (value.Low & 0x80000000) != 0 ? 1u : 0u;
 162            uint c1 = (value.Mid & 0x80000000) != 0 ? 1u : 0u;
 163            value.Low = value.Low << 1;
 164            value.Mid = (value.Mid << 1) | c0;
 165            value.High = (value.High << 1) | c1;
 166        }
 67
 68        private static void DecAdd(ref MutableDecimal value, MutableDecimal d)
 169        {
 170            if (D32AddCarry(ref value.Low, d.Low))
 171            {
 172                if (D32AddCarry(ref value.Mid, 1))
 173                {
 174                    D32AddCarry(ref value.High, 1);
 175                }
 176            }
 77
 178            if (D32AddCarry(ref value.Mid, d.Mid))
 179            {
 180                D32AddCarry(ref value.High, 1);
 181            }
 82
 183            D32AddCarry(ref value.High, d.High);
 184        }
 85    }
 86}