MCPcopy Create free account
hub / github.com/apache/fory / FromParts

Method FromParts

csharp/src/Fory/DecimalSerializer.cs:58–76  ·  view source on GitHub ↗
(int scale, BigInteger unscaled)

Source from the content-addressed store, hash-verified

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
79internal sealed class ForyDecimalSerializer : Serializer<ForyDecimal>

Callers

nothing calls this directly

Calls 1

AbsMethod · 0.80

Tested by

no test coverage detected