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.
91 92 93 94 95 |
# File '../../src/modules/Integer.rb', line 91 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, … .
61 62 63 |
# File '../../src/modules/Integer.rb', line 61 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.
84 85 86 87 88 |
# File '../../src/modules/Integer.rb', line 84 def Max(values) return nil unless values values.max end |
- (Object) Min(values)
Returns the smallest integer in values.
Behaviour is undefined for empty values.
75 76 77 78 79 |
# File '../../src/modules/Integer.rb', line 75 def Min(values) return nil unless values values.min 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.
50 51 52 53 54 55 56 57 58 |
# File '../../src/modules/Integer.rb', line 50 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.
66 67 68 69 70 |
# File '../../src/modules/Integer.rb', line 66 def Sum(values) return nil unless values values.reduce(0, :+) end |