Class: Yast::IntegerClass

Inherits:
Module
  • Object
show all
Defined in:
library/types/src/modules/Integer.rb

Instance Method Summary collapse

Instance Method Details

#Clamp(i, min, max) ⇒ Object

Clamps the integer i.



91
92
93
94
95
# File 'library/types/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

#IsPowerOfTwo(i) ⇒ Object

Checks whether i is a power of two. That is 1, 2, 4, 8, … .



61
62
63
# File 'library/types/src/modules/Integer.rb', line 61

def IsPowerOfTwo(i)
  Ops.greater_than(i, 0) && Ops.bitwise_and(i, Ops.subtract(i, 1)) == 0
end

#mainObject



34
35
36
# File 'library/types/src/modules/Integer.rb', line 34

def main
  textdomain "base"
end

#Max(values) ⇒ Object

Returns the highest integer in values.

Behaviour is undefined for empty values.



84
85
86
87
88
# File 'library/types/src/modules/Integer.rb', line 84

def Max(values)
  return nil unless values

  values.max
end

#Min(values) ⇒ Object

Returns the smallest integer in values.

Behaviour is undefined for empty values.



75
76
77
78
79
# File 'library/types/src/modules/Integer.rb', line 75

def Min(values)
  return nil unless values

  values.min
end

#Range(stop) ⇒ Object

Generate a list<integer> with the integers from 0 to stop - 1.



39
40
41
42
43
44
45
46
47
# File 'library/types/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

#RangeFrom(start, stop) ⇒ Object

Generate a list<integer> with the integers from start to stop - 1.



50
51
52
53
54
55
56
57
58
# File 'library/types/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

#Sum(values) ⇒ Object

Calculates the sum of values.



66
67
68
69
70
# File 'library/types/src/modules/Integer.rb', line 66

def Sum(values)
  return nil unless values

  values.reduce(0, :+)
end