-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathInteger.wurst
More file actions
66 lines (51 loc) · 2.07 KB
/
Integer.wurst
File metadata and controls
66 lines (51 loc) · 2.07 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
package Integer
import NoWurst
import Real
import BasicTypeClasses
public constant INT_MAX = 2147483647
public constant INT_MIN = -2147483648
/** Returns the absolute value of this int */
public function int.abs() returns int
return this < 0 ? -this : this
/** Returns the square of this int */
public function int.squared() returns int
return this * this
/** returns the sign of the int */
public function int.sign() returns int
return (this > 0 ? 1 : (this < 0 ? -1 : 0))
/** Limits this int to the given range */
public function int.clamp(int lowerBound, int higherBound) returns int
return (this <= lowerBound ? lowerBound : (this >= higherBound ? higherBound : this))
/** Returns the int as real */
public function int.toReal() returns real
return this * 1.
/** Returns the string representation of this int */
public function int.toString() returns string
return I2S(this)
public implements Show<int>
override function toString(int b) returns string
return b.toString()
/** Returns this int to the power of the argument int */
public function int.pow(int x) returns int
int result = 1
for int i=1 to x
result *= this
return result
/** Linear Interpolation with alphafactor(smoothness) */
public function int.lerp(int target, real alpha) returns int
return ((this * (1 - alpha)) + (target * alpha)).round()
/** Checks if this int is between low and high value */
public function int.isBetween(int low, int high) returns bool
return this >= low and this <= high
/** Returns the result of a bitwise AND operation performed on this int and the argument int. */
public function int.bitAnd(int other) returns int
return BlzBitAnd(this, other)
/** Returns the result of a bitwise OR operation performed on this int and the argument int. */
public function int.bitOr(int other) returns int
return BlzBitOr(this, other)
/** Returns the result of a bitwise exclusive OR operation performed on this int and the argument int. */
public function int.bitXor(int other) returns int
return BlzBitXor(this, other)
public implements Default<int>
override function defaultValue() returns int
return 0