Class: Yast::IntegerClass
- Inherits:
-
Module
- Object
- Module
- Yast::IntegerClass
- Defined in:
- ../../src/modules/Integer.rb
Instance Method Summary (collapse)
-
- (Object) Clamp(i, min, max)
Clamps the integer i.
-
- (Object) IsPowerOfTwo(i)
Checks whether i is a power of two.
- - (Object) main
-
- (Object) Max(values)
Returns the highest integer in values.
-
- (Object) Min(values)
Returns the smallest integer in values.
-
- (Object) Range(stop)
Generate a list with the integers from 0 to stop - 1.
-
- (Object) RangeFrom(start, stop)
Generate a list with the integers from start to stop - 1.
-
- (Object) Sum(values)
Calculates the sum of values.
Instance Method Details
- (Object) Clamp(i, min, max)
Clamps the integer i.
94 95 96 97 98 |
# File '../../src/modules/Integer.rb', line 94 def Clamp(i, min, max) return min if Ops.less_than(i, min) return max if Ops.greater_than(i, max) i end |
- (Object) IsPowerOfTwo(i)
Checks whether i is a power of two. That is 1, 2, 4, 8, … .
63 64 65 |
# File '../../src/modules/Integer.rb', line 63 def IsPowerOfTwo(i) Ops.greater_than(i, 0) && Ops.bitwise_and(i, Ops.subtract(i, 1)) == 0 end |
- (Object) main
34 35 36 |
# File '../../src/modules/Integer.rb', line 34 def main textdomain "base" end |
- (Object) Max(values)
Returns the highest integer in values.
Behaviour is undefined for empty values.
87 88 89 90 |
# File '../../src/modules/Integer.rb', line 87 def Max(values) values = deep_copy(values) Builtins::List.reduce(values) { |x, y| Ops.greater_than(x, y) ? x : y } end |
- (Object) Min(values)
Returns the smallest integer in values.
Behaviour is undefined for empty values.
78 79 80 81 |
# File '../../src/modules/Integer.rb', line 78 def Min(values) values = deep_copy(values) Builtins::List.reduce(values) { |x, y| Ops.less_than(x, y) ? x : y } end |
- (Object) Range(stop)
Generate a list<integer> with the integers from 0 to stop - 1.
39 40 41 42 43 44 45 46 47 |
# File '../../src/modules/Integer.rb', line 39 def Range(stop) ret = [] i = 0 while Ops.less_than(i, stop) ret = Builtins.add(ret, i) i = Ops.add(i, 1) end deep_copy(ret) end |
- (Object) RangeFrom(start, stop)
Generate a list<integer> with the integers from start to stop - 1.
51 52 53 54 55 56 57 58 59 |
# File '../../src/modules/Integer.rb', line 51 def RangeFrom(start, stop) ret = [] i = start while Ops.less_than(i, stop) ret = Builtins.add(ret, i) i = Ops.add(i, 1) end deep_copy(ret) end |
- (Object) Sum(values)
Calculates the sum of values.
69 70 71 72 |
# File '../../src/modules/Integer.rb', line 69 def Sum(values) values = deep_copy(values) Builtins::List.reduce(0, values) { |x, y| Ops.add(x, y) } end |