@@ -7,19 +7,59 @@ import fr.hammons.slinc.ShortDescriptor
7
7
import fr .hammons .slinc .IntDescriptor
8
8
9
9
object IntegralAlias :
10
+ def min [T ](using a : Alias [T ]): Long = a.aliases.applyOrElse(
11
+ (os, arch),
12
+ _ => throw new Error (s " Alias for ${a.name} not defined for this platform " )
13
+ ) match
14
+ case ByteDescriptor => Byte .MinValue .toLong
15
+ case ShortDescriptor => Short .MinValue .toLong
16
+ case IntDescriptor => Int .MinValue .toLong
17
+ case LongDescriptor => Long .MinValue
18
+ case _ =>
19
+ throw new Error (
20
+ s " ${a.name} is not an alias for an integral type on $os $arch"
21
+ )
22
+
23
+ def max [T ](using a : Alias [T ]): Long = a.aliases.applyOrElse(
24
+ (os, arch),
25
+ _ => throw new Error (s " Alias for ${a.name} not defined for this platform " )
26
+ ) match
27
+ case ByteDescriptor => Byte .MaxValue .toLong
28
+ case ShortDescriptor => Short .MaxValue .toLong
29
+ case IntDescriptor => Int .MaxValue .toLong
30
+ case LongDescriptor => Long .MaxValue
31
+ case _ =>
32
+ throw new Error (
33
+ s " ${a.name} is not an alias for an integral type on $os $arch"
34
+ )
35
+
10
36
def range [T ](using a : Alias [T ]) = a.aliases.applyOrElse(
11
37
(os, arch),
12
38
_ => throw new Error (s " Alias for ${a.name} not defined for this platform " )
13
39
) match
14
- case ByteDescriptor => Byte .MinValue to Byte .MaxValue
15
- case ShortDescriptor => Short .MinValue to Short .MaxValue
16
- case IntDescriptor => Int .MinValue to Int .MaxValue
17
- case LongDescriptor => Long .MinValue to Long .MaxValue
40
+ case ByteDescriptor => Range .Long .inclusive(Byte .MinValue , Byte .MaxValue , 1 )
41
+ case ShortDescriptor =>
42
+ Range .Long .inclusive(Short .MinValue , Short .MaxValue , 1 )
43
+ case IntDescriptor => Range .Long .inclusive(Int .MinValue , Int .MaxValue , 1 )
44
+ case LongDescriptor => Long .MinValue to Long .MaxValue
18
45
case _ =>
19
46
throw new Error (
20
47
s " ${a.name} is not an alias for an integral type on $os $arch"
21
48
)
22
49
50
+ def toLong [T ](value : T )(using a : Alias [T ]) = a.aliases.applyOrElse(
51
+ (os, arch),
52
+ _ => throw new Error (s " Alias for ${a.name} not defined for this platform " )
53
+ ) match
54
+ case ByteDescriptor => value.asInstanceOf [Byte ].toLong
55
+ case ShortDescriptor => value.asInstanceOf [Short ].toLong
56
+ case IntDescriptor => value.asInstanceOf [Int ].toLong
57
+ case LongDescriptor => value.asInstanceOf [Long ].toLong
58
+ case _ =>
59
+ throw new Error (
60
+ s " ${a.name} is not an alias for an integral type on $os - $arch"
61
+ )
62
+
23
63
def transform [T ]: Transform [T ] = Transform [T ]
24
64
class Transform [T ]:
25
65
def apply [U ](value : U )(using a : Alias [T ], n : Numeric [U ]) =
0 commit comments