Class: Float

Inherits:
Object
  • Object
show all
Defined in:
lib/overloading/float.rb

Overview

Overloading operators for Float. Operations that are oveloaded are:

  • ‘overloaded_plus` for `+`

  • ‘overloaded_minus` for `-`

  • ‘overloaded_mul` for `*`

  • ‘overloaded_div` for `/`

  • ‘overloaded_pow` for `**`

Instance Method Summary collapse

Instance Method Details

#*(a) ⇒ Object

If ‘a` is a `CAS::Op` transform self in a `CAS::Const` and return a symbolic operation



64
65
66
67
# File 'lib/overloading/float.rb', line 64

def *(a)
  return (CAS::const(self) * a) if a.is_a? CAS::Op
  self.overloaded_mul a
end

#**(a) ⇒ Object

If ‘a` is a `CAS::Op` transform self in a `CAS::Const` and return a symbolic operation



80
81
82
83
# File 'lib/overloading/float.rb', line 80

def **(a)
  return (CAS::const(self) ** a) if a.is_a? CAS::Op
  self.overloaded_pow a
end

#+(a) ⇒ Object

If ‘a` is a `CAS::Op` transform self in a `CAS::Const` and return a symbolic operation. If



48
49
50
51
# File 'lib/overloading/float.rb', line 48

def +(a)
  return (CAS::const(self) + a) if a.is_a? CAS::Op
  self.overloaded_plus a
end

#-(a) ⇒ Object

If ‘a` is a `CAS::Op` transform self in a `CAS::Const` and return a symbolic operation



56
57
58
59
# File 'lib/overloading/float.rb', line 56

def -(a)
  return (CAS::const(self) - a) if a.is_a? CAS::Op
  self.overloaded_minus a
end

#/(a) ⇒ Object

If ‘a` is a `CAS::Op` transform self in a `CAS::Const` and return a symbolic operation



72
73
74
75
# File 'lib/overloading/float.rb', line 72

def /(a)
  return (CAS::const(self) / a) if a.is_a? CAS::Op
  self.overloaded_div a
end

#overloaded_divObject



40
# File 'lib/overloading/float.rb', line 40

alias :overloaded_div   :/

#overloaded_minusObject



38
# File 'lib/overloading/float.rb', line 38

alias :overloaded_minus :-

#overloaded_mulObject



39
# File 'lib/overloading/float.rb', line 39

alias :overloaded_mul   :*

#overloaded_plusObject

Setting aliases



37
# File 'lib/overloading/float.rb', line 37

alias :overloaded_plus  :+

#overloaded_powObject



41
# File 'lib/overloading/float.rb', line 41

alias :overloaded_pow   :**