• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Giorgi / DuckDB.NET / 22237670288

20 Feb 2026 07:15PM UTC coverage: 89.875% (+0.2%) from 89.659%
22237670288

push

github

Giorgi
Fix decimal precision and support scale > 28

Replace lossy double-based Math.Pow(10, scale) with
pre-computed decimal and BigInteger lookup tables.

Use direct decimal constructor and mantissa extraction
instead of arithmetic reconstruction, avoiding
intermediate precision loss.

Handle HugeInt decimals with scale > 28 (beyond .NET
decimal's maximum) by truncating excess digits via
BigInteger division.

1236 of 1431 branches covered (86.37%)

Branch coverage included in aggregate %.

76 of 76 new or added lines in 5 files covered. (100.0%)

11 existing lines in 3 files now uncovered.

2510 of 2737 relevant lines covered (91.71%)

523497.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.77
/DuckDB.NET.Data/Extensions/TypeExtensions.cs
1
using System.Diagnostics.CodeAnalysis;
2
using System.Runtime.CompilerServices;
3

4
namespace DuckDB.NET.Data.Extensions;
5

6
internal static class TypeExtensions
7
{
8
    private static readonly HashSet<Type> FloatingNumericTypes = [typeof(decimal), typeof(float), typeof(double)];
3✔
9

10
    private static readonly HashSet<Type> IntegralNumericTypes =
3✔
11
    [
3✔
12
        typeof(byte), typeof(sbyte),
3✔
13
        typeof(short), typeof(ushort),
3✔
14
        typeof(int), typeof(uint),
3✔
15
        typeof(long), typeof(ulong),
3✔
16
        typeof(BigInteger)
3✔
17
    ];
3✔
18

19
    private static readonly Dictionary<Type, DuckDBType> ClrToDuckDBTypeMap = new()
3✔
20
    {
3✔
21
        { typeof(bool), DuckDBType.Boolean },
3✔
22
        { typeof(sbyte), DuckDBType.TinyInt },
3✔
23
        { typeof(short), DuckDBType.SmallInt },
3✔
24
        { typeof(int), DuckDBType.Integer },
3✔
25
        { typeof(long), DuckDBType.BigInt },
3✔
26
        { typeof(byte), DuckDBType.UnsignedTinyInt },
3✔
27
        { typeof(ushort), DuckDBType.UnsignedSmallInt },
3✔
28
        { typeof(uint), DuckDBType.UnsignedInteger },
3✔
29
        { typeof(ulong), DuckDBType.UnsignedBigInt },
3✔
30
        { typeof(float), DuckDBType.Float },
3✔
31
        { typeof(double), DuckDBType.Double},
3✔
32
        { typeof(Guid), DuckDBType.Uuid},
3✔
33
        { typeof(DateTime), DuckDBType.Timestamp},
3✔
34
        { typeof(TimeSpan), DuckDBType.Interval},
3✔
35
        { typeof(DateOnly), DuckDBType.Date},
3✔
36
        { typeof(TimeOnly), DuckDBType.Time},
3✔
37
        { typeof(DateTimeOffset), DuckDBType.TimestampTz},
3✔
38
        { typeof(BigInteger), DuckDBType.HugeInt},
3✔
39
        { typeof(string), DuckDBType.Varchar},
3✔
40
        { typeof(decimal), DuckDBType.Decimal},
3✔
41
        { typeof(object), DuckDBType.Any},
3✔
42
    };
3✔
43

44
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
45
    public static bool IsNull([NotNullWhen(false)] this object? value) => value is null or DBNull;
12,701✔
46

47
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
48
    public static Type UnderlyingTypeOrSelf(this Type type) => Nullable.GetUnderlyingType(type) ?? type;
612✔
49

50
    public static (bool isNullableValueType, Type type) IsNullableValueType<T>()
51
    {
52
        var targetType = typeof(T);
5,628,264✔
53

54
        var isNullableValueType = default(T) is null && targetType.IsValueType;
5,628,264✔
55

56
        return (isNullableValueType, targetType);
5,628,264✔
57
    }
58

59
    public static bool IsFloatingNumericType<T>()
60
    {
61
        return FloatingNumericTypes.Contains(typeof(T));
2,789,988✔
62
    }
63

64
    public static bool IsIntegralNumericType<T>()
65
    {
66
        return IntegralNumericTypes.Contains(typeof(T));
2,789,988✔
67
    }
68

69
    public static bool IsNumeric(this Type type)
70
    {
71
        return IntegralNumericTypes.Contains(type) || FloatingNumericTypes.Contains(type);
10,661,794✔
72
    }
73

74
    public static bool AllowsNullValue(this Type type, out bool isNullableValueType, out Type? underlyingType)
75
    {
76
        underlyingType = Nullable.GetUnderlyingType(type);
1,041,088✔
77
        isNullableValueType = underlyingType != null;
1,041,088✔
78

79
        var isNullable = isNullableValueType || !type.IsValueType;
1,041,088✔
80

81
        return isNullable;
307,533✔
82
    }
83

84
    public static DuckDBLogicalType GetLogicalType<T>() => GetLogicalType(typeof(T));
102✔
85

86
    public static DuckDBLogicalType GetLogicalType(this Type type)
87
    {
88
        type = type.UnderlyingTypeOrSelf();
585✔
89

90
        if (type == typeof(decimal))
585✔
91
        {
92
            return NativeMethods.LogicalType.DuckDBCreateDecimalType(38, 18);
15✔
93
        }
94

95
        if (ClrToDuckDBTypeMap.TryGetValue(type, out var duckDBType))
570!
96
        {
97
            return NativeMethods.LogicalType.DuckDBCreateLogicalType(duckDBType);
570✔
98
        }
99

UNCOV
100
        throw new InvalidOperationException($"Cannot map type {type.FullName} to DuckDBType.");
×
101
    }
102

103
    public static DuckDBType GetDuckDBType(this Type type) => ClrToDuckDBTypeMap.TryGetValue(type, out var duckDBType) ? duckDBType : DuckDBType.Invalid;
27!
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc