forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberInfo.cs
More file actions
99 lines (97 loc) · 3.4 KB
/
NumberInfo.cs
File metadata and controls
99 lines (97 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Numerics;
using NumSharp.Backends;
namespace NumSharp.Utilities
{
public static class NumberInfo
{
/// <summary>
/// Get the min value of given <see cref="NPTypeCode"/>.
/// </summary>
public static object MaxValue(this NPTypeCode typeCode)
{
switch (typeCode)
{
case NPTypeCode.Complex:
return new Complex(double.MaxValue, double.MaxValue);
case NPTypeCode.Boolean:
return true;
#if _REGEN
%foreach except(supported_primitives, "Boolean", "String")%
case NPTypeCode.#1:
return #1.MaxValue;
%
#else
case NPTypeCode.Byte:
return Byte.MaxValue;
case NPTypeCode.Int16:
return Int16.MaxValue;
case NPTypeCode.UInt16:
return UInt16.MaxValue;
case NPTypeCode.Int32:
return Int32.MaxValue;
case NPTypeCode.UInt32:
return UInt32.MaxValue;
case NPTypeCode.Int64:
return Int64.MaxValue;
case NPTypeCode.UInt64:
return UInt64.MaxValue;
case NPTypeCode.Char:
return Char.MaxValue;
case NPTypeCode.Double:
return Double.MaxValue;
case NPTypeCode.Single:
return Single.MaxValue;
case NPTypeCode.Decimal:
return Decimal.MaxValue;
#endif
default:
throw new ArgumentOutOfRangeException(nameof(typeCode), typeCode, null);
}
}
/// <summary>
/// Get the min value of given <see cref="NPTypeCode"/>.
/// </summary>
public static object MinValue(this NPTypeCode typeCode)
{
switch (typeCode)
{
case NPTypeCode.Complex:
return new Complex(double.MinValue, double.MinValue);
case NPTypeCode.Boolean:
return false;
#if _REGEN
%foreach except(supported_primitives, "Boolean", "String")%
case NPTypeCode.#1:
return #1.MinValue;
%
#else
case NPTypeCode.Byte:
return Byte.MinValue;
case NPTypeCode.Int16:
return Int16.MinValue;
case NPTypeCode.UInt16:
return UInt16.MinValue;
case NPTypeCode.Int32:
return Int32.MinValue;
case NPTypeCode.UInt32:
return UInt32.MinValue;
case NPTypeCode.Int64:
return Int64.MinValue;
case NPTypeCode.UInt64:
return UInt64.MinValue;
case NPTypeCode.Char:
return Char.MinValue;
case NPTypeCode.Double:
return Double.MinValue;
case NPTypeCode.Single:
return Single.MinValue;
case NPTypeCode.Decimal:
return Decimal.MinValue;
#endif
default:
throw new ArgumentOutOfRangeException(nameof(typeCode), typeCode, null);
}
}
}
}