| 56 | } |
| 57 | |
| 58 | private static decimal FromParts(int scale, BigInteger unscaled) |
| 59 | { |
| 60 | if (scale is < 0 or > 28) |
| 61 | { |
| 62 | throw new InvalidDataException($"decimal scale {scale} is outside System.Decimal range"); |
| 63 | } |
| 64 | |
| 65 | bool negative = unscaled.Sign < 0; |
| 66 | BigInteger magnitude = BigInteger.Abs(unscaled); |
| 67 | if ((magnitude >> 96) != BigInteger.Zero) |
| 68 | { |
| 69 | throw new InvalidDataException("decimal magnitude exceeds System.Decimal range"); |
| 70 | } |
| 71 | |
| 72 | int lo = unchecked((int)(uint)(magnitude & UInt32Mask)); |
| 73 | int mid = unchecked((int)(uint)((magnitude >> 32) & UInt32Mask)); |
| 74 | int hi = unchecked((int)(uint)((magnitude >> 64) & UInt32Mask)); |
| 75 | return new decimal(lo, mid, hi, negative, (byte)scale); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | internal sealed class ForyDecimalSerializer : Serializer<ForyDecimal> |