| | | 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 | | |
| | | 4 | | namespace System.Reflection.Internal |
| | | 5 | | { |
| | | 6 | | internal static class DecimalUtilities |
| | | 7 | | { |
| | | 8 | | public static int GetScale(this decimal value) |
| | 0 | 9 | | { |
| | 0 | 10 | | Span<int> bits = [0, 0, 0, 0]; |
| | 0 | 11 | | decimal.GetBits(value, bits); |
| | 0 | 12 | | return unchecked((byte)(bits[3] >> 16)); |
| | 0 | 13 | | } |
| | | 14 | | |
| | | 15 | | public static void GetBits(this decimal value, out bool isNegative, out byte scale, out uint low, out uint mid, |
| | 0 | 16 | | { |
| | 0 | 17 | | Span<int> bits = [0, 0, 0, 0]; |
| | 0 | 18 | | decimal.GetBits(value, bits); |
| | | 19 | | |
| | | 20 | | // 'bits' is a four-element buffer of 32-bit signed integers. |
| | | 21 | | // The first, second, and third elements contain the low, middle, and high 32 bits of the 96-bit integer num |
| | 0 | 22 | | low = unchecked((uint)bits[0]); |
| | 0 | 23 | | mid = unchecked((uint)bits[1]); |
| | 0 | 24 | | high = unchecked((uint)bits[2]); |
| | | 25 | | |
| | | 26 | | // The fourth element of the returned array contains the scale factor and sign. It consists of the following |
| | | 27 | | // Bits 0 to 15, the lower word, are unused and must be zero. |
| | | 28 | | // Bits 16 to 23 must contain an exponent between 0 and 28, which indicates the power of 10 to divide the in |
| | | 29 | | // Bits 24 to 30 are unused and must be zero. |
| | | 30 | | // Bit 31 contains the sign; 0 meaning positive, and 1 meaning negative. |
| | 0 | 31 | | scale = unchecked((byte)(bits[3] >> 16)); |
| | 0 | 32 | | isNegative = (bits[3] & 0x80000000) != 0; |
| | 0 | 33 | | } |
| | | 34 | | } |
| | | 35 | | } |
| | | 36 | | |