Repository navigation
Expand file tree
/
Copy pathlimit.v
More file actions
72 lines (70 loc) · 1.55 KB
/
Copy pathlimit.v
File metadata and controls
72 lines (70 loc) · 1.55 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
// Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module math
// maxof returns the maximum value of the type `T`
@[inline]
pub fn maxof[T]() T {
$if T is i8 {
return max_i8
} $else $if T is i16 {
return max_i16
} $else $if T is i32 {
return max_i32
} $else $if T is i32 {
return max_i32
} $else $if T is i64 {
return max_i64
} $else $if T is u8 {
return max_u8
} $else $if T is byte {
return max_u8
} $else $if T is u16 {
return max_u16
} $else $if T is u32 {
return max_u32
} $else $if T is u64 {
return max_u64
} $else $if T is f32 {
return max_f32
} $else $if T is f64 {
return max_f64
} $else $if T is int {
return max_int
} $else {
panic('A maximum value of the type `' + typeof[T]().name + '` is not defined.')
}
}
// minof returns the minimum value of the type `T`
@[inline]
pub fn minof[T]() T {
$if T is i8 {
return min_i8
} $else $if T is i16 {
return min_i16
} $else $if T is i32 {
return min_i32
} $else $if T is i32 {
return min_i32
} $else $if T is i64 {
return min_i64
} $else $if T is u8 {
return min_u8
} $else $if T is byte {
return min_u8
} $else $if T is u16 {
return min_u16
} $else $if T is u32 {
return min_u32
} $else $if T is u64 {
return min_u64
} $else $if T is f32 {
return -max_f32
} $else $if T is f64 {
return -max_f64
} $else $if T is int {
return min_int
} $else {
panic('A minimum value of the type `' + typeof[T]().name + '` is not defined.')
}
}