Class: Yast::IntegerClass

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

Instance Method Summary collapse

Instance Method Details

#Clamp(number, min, max) ⇒ Object

Clamps the integer i.



89
90
91
92
93
94
# File 'library/types/src/modules/Integer.rb', line 89

def Clamp(number, min, max)
  return min if Ops.less_than(number, min)
  return max if Ops.greater_than(number, max)

  number
end

#IsPowerOfTwo(input) ⇒ Object

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



59
60
61
# File 'library/types/src/modules/Integer.rb', line 59

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

#mainObject



32
33
34
# File 'library/types/src/modules/Integer.rb', line 32

def main
  textdomain "base"
end

#Max(values) ⇒ Object

Returns the highest integer in values.

Behaviour is undefined for empty values.



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

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.



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

def Min(values)
  return nil unless values

  values.min
end

#Range(stop) ⇒ Object

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



37
38
39
40
41
42
43
44
45
# File 'library/types/src/modules/Integer.rb', line 37

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 with the integers from start to stop - 1.



48
49
50
51
52
53
54
55
56
# File 'library/types/src/modules/Integer.rb', line 48

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.



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

def Sum(values)
  return nil unless values

  values.reduce(0, :+)
end