Module: Klam::Primitives::Arithmetic

Included in:
Environment
Defined in:
lib/klam/primitives/arithmetic.rb

Instance Method Summary collapse

Instance Method Details

#*(a, b) ⇒ Object



12
13
14
# File 'lib/klam/primitives/arithmetic.rb', line 12

def *(a, b)
  a * b
end

#+(a, b) ⇒ Object



4
5
6
# File 'lib/klam/primitives/arithmetic.rb', line 4

def +(a, b)
  a + b
end

#-(a, b) ⇒ Object



8
9
10
# File 'lib/klam/primitives/arithmetic.rb', line 8

def -(a, b)
  a - b
end

#/(a, b) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/klam/primitives/arithmetic.rb', line 16

def /(a, b)
  # Kl does not make a distinction between integers and reals.  Dividing
  # the integer 3 by the interger 2 must yield 1.5 rather than 1.  We'd
  # like to keep things in integers as much as possible, so we coerce a
  # to a float only if integer division is not possible.
  if a.kind_of?(Integer) && b.kind_of?(Integer) && a.remainder(b) != 0
    a = a.to_f
  end

  a / b
end

#<(a, b) ⇒ Object



28
29
30
# File 'lib/klam/primitives/arithmetic.rb', line 28

def <(a, b)
  a < b
end

#<=(a, b) ⇒ Object



36
37
38
# File 'lib/klam/primitives/arithmetic.rb', line 36

def <=(a, b)
  a <= b
end

#>(a, b) ⇒ Object



32
33
34
# File 'lib/klam/primitives/arithmetic.rb', line 32

def >(a, b)
  a > b
end

#>=(a, b) ⇒ Object



40
41
42
# File 'lib/klam/primitives/arithmetic.rb', line 40

def >=(a, b)
  a >= b
end

#number?(a) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/klam/primitives/arithmetic.rb', line 44

def number?(a)
  a.kind_of?(Numeric)
end