|
| 1 | + |
| 2 | +Namespace stdlib.syntax |
| 3 | + |
| 4 | +'Minilib minmax |
| 5 | +'iDkP from GaragePixel |
| 6 | +'Since 2018-2025 |
| 7 | + |
| 8 | +'Note: In monkey library, the bad implemented min/max functions must be deactivated |
| 9 | +'in order to make the multitypes min/max functions to works |
| 10 | + |
| 11 | +Function Min<T>:T(a:T,b:T) Where T Implements INumeric |
| 12 | + 'the limit value, if returned, is casted to the initial type |
| 13 | + Return a<b ? a Else b |
| 14 | +End |
| 15 | + |
| 16 | +Function Min<T1,T2>:T1(a:T1,b:T2) Where T1 Implements INumeric And |
| 17 | + T2 Implements INumeric |
| 18 | + 'the limit value, if returned, is casted to the initial type |
| 19 | + Return Cast<T1>(a<b ? a Else b) |
| 20 | +End |
| 21 | + |
| 22 | + |
| 23 | +Function Min<T>:T Ptr(a:T Ptr,b:T Ptr) Where T Implements INumeric |
| 24 | + |
| 25 | + Return a[0]<b[0] ? a Else b |
| 26 | +End |
| 27 | + |
| 28 | +Function Min<T>:T(a:T Ptr,b:T Ptr) Where T Implements INumeric |
| 29 | + 'return type overload? |
| 30 | + Return a[0]<b[0] ? a[0] Else b[0] |
| 31 | +End |
| 32 | + |
| 33 | +Function Min<T1,T2>:T1(a:T1 Ptr,b:T2 Ptr) Where T1 Implements INumeric And |
| 34 | + T2 Implements INumeric |
| 35 | + 'the limit value, if returned, is casted to the initial type |
| 36 | + Return Cast<T1>(a[0]<b[0] ? a[0] Else b[0]) |
| 37 | +End |
| 38 | + |
| 39 | +Function Min<T>:T(a:T,b:T,c:T) Where T Implements INumeric |
| 40 | + |
| 41 | + '3 arguments breaks the overloading of the language min/max stuff |
| 42 | + 'So the language library non-native stuff was undoned, |
| 43 | + 'and in the the word we'll have peace! |
| 44 | + |
| 45 | + Return a<b ? (a<c ? a Else c) Else (b<c ? c Else b) |
| 46 | +End |
| 47 | + |
| 48 | +Function Min<T>:T Ptr(a:T Ptr,b:T Ptr,c:T Ptr) Where T Implements INumeric |
| 49 | + |
| 50 | + Return a[0]<b[0] ? (a[0]<c[0] ? c Else a) Else (b[0]<c[0] ? c Else b) |
| 51 | +End |
| 52 | + |
| 53 | +Function Min<T1,T2,T3>:T1(a:T1,b:T2,c:T3) Where T1 Implements INumeric And |
| 54 | + T2 Implements INumeric And |
| 55 | + T3 Implements INumeric |
| 56 | + 'the limit value, if returned, is casted to the initial type |
| 57 | + Return Cast<T1>(a<b ? (a<c ? a Else c) Else (b<c ? b Else c)) |
| 58 | +End |
| 59 | + |
| 60 | +Function Min<T1,T2,T3>:T1(a:T1 Ptr,b:T2 Ptr,c:T3 Ptr) Where T1 Implements INumeric And |
| 61 | + T2 Implements INumeric And |
| 62 | + T3 Implements INumeric |
| 63 | + 'the limit value, if returned, is casted to the initial type |
| 64 | + Return Cast<T1>(a[0]<b[0] ? (a[0]<c[0] ? a[0] Else c[0]) Else (b[0]<c[0] ? b[0] Else c[0])) |
| 65 | +End |
| 66 | + |
| 67 | +Function Max<T>:T(a:T,b:T) Where T Implements INumeric |
| 68 | + Return a<b ? b Else a |
| 69 | +End |
| 70 | + |
| 71 | +Function Max<T1,T2>:T1(a:T1,b:T2) Where T1 Implements INumeric And |
| 72 | + T2 Implements INumeric |
| 73 | + Return a<b ? b Else a |
| 74 | +End |
| 75 | + |
| 76 | +Function Max<T>:T Ptr(a:T Ptr,b:T Ptr) Where T Implements INumeric |
| 77 | + |
| 78 | + Return a[0]<b[0] ? b Else a |
| 79 | +End |
| 80 | + |
| 81 | +Function Max<T1,T2>:T1(a:T1 Ptr,b:T2 Ptr) Where T1 Implements INumeric And |
| 82 | + T2 Implements INumeric |
| 83 | + 'the limit value, if returned, is casted to the initial type |
| 84 | + Return Cast<T1>(a[0]<b[0] ? b[0] Else a[0]) |
| 85 | +End |
| 86 | + |
| 87 | +Function Max<T>:T(a:T,b:T,c:T) Where T Implements INumeric |
| 88 | + |
| 89 | + Return a<b ? (b<c ? c Else b) Else (a<c ? c Else a) |
| 90 | +End |
| 91 | + |
| 92 | +Function Max<T>:T(a:T Ptr,b:T Ptr,c:T Ptr) Where T Implements INumeric |
| 93 | + |
| 94 | + Return a[0]<b[0] ? (b[0]<c[0] ? c Else b) Else (a[0]<c[0] ? c[0] Else a[0]) |
| 95 | +End |
| 96 | + |
| 97 | +Function Max<T1,T2,T3>:T1(a:T1,b:T2,c:T3) Where T1 Implements INumeric And |
| 98 | + T2 Implements INumeric And |
| 99 | + T3 Implements INumeric |
| 100 | + 'the limit value, if returned, is casted to the initial type |
| 101 | + Return Cast<T1>(a<b ? (b<c ? c Else b) Else (a<c ? c Else a)) |
| 102 | +End |
| 103 | + |
| 104 | +Function Max<T1,T2,T3>:T1(a:T1 Ptr,b:T2 Ptr,c:T3 Ptr) Where T1 Implements INumeric And |
| 105 | + T2 Implements INumeric And |
| 106 | + T3 Implements INumeric |
| 107 | + 'the limit value, if returned, is casted to the initial type |
| 108 | + 'Note that byte with int,float,double are incompatible |
| 109 | + Return Cast<T1>(a[0]<b[0] ? (b[0]<c[0] ? c[0] Else b[0]) Else (a[0]<c[0] ? c[0] Else a[0])) |
| 110 | +End |
0 commit comments