Class: NumRu::UNumeric::Num2Coerce

Inherits:
Object
  • Object
show all
Defined in:
lib/numru/gphys/unumeric.rb

Overview

Tentative class to assist basic arithmetic operations between quantities without (like Numeric) and with (like UNumeric) units.

The fundamental problem here is that the desired unit conversion to convert the Numeric is different between additional methods (+,-) and multiplicative methods (*,/). In the former, the numeric should be converted to have the same units with the other operand, and in the latter, it should be non-dimensional.

Instance Method Summary collapse

Constructor Details

#initialize(num) ⇒ Num2Coerce

  • num (Numeric, NArray etc – numeric-like object without units). It must be KNOWN by the other operand.



200
201
202
# File 'lib/numru/gphys/unumeric.rb', line 200

def initialize(num)
  @num = num
end

Instance Method Details

#*(o) ⇒ Object



208
# File 'lib/numru/gphys/unumeric.rb', line 208

def *(o); o * num; end

#+(o) ⇒ Object



206
# File 'lib/numru/gphys/unumeric.rb', line 206

def +(o); o + num; end

#-(o) ⇒ Object



207
# File 'lib/numru/gphys/unumeric.rb', line 207

def -(o); (-o) + num; end

#/(o) ⇒ Object



209
# File 'lib/numru/gphys/unumeric.rb', line 209

def /(o); o**(-1) * num;end

#<(o) ⇒ Object



212
# File 'lib/numru/gphys/unumeric.rb', line 212

def <(o); o>num; end

#<=(o) ⇒ Object



214
# File 'lib/numru/gphys/unumeric.rb', line 214

def <=(o); o>=num; end

#<=>(o) ⇒ Object



218
# File 'lib/numru/gphys/unumeric.rb', line 218

def <=>(o); c = o<=>num or -c; end

#==(o) ⇒ Object



215
# File 'lib/numru/gphys/unumeric.rb', line 215

def ==(o); o==num; end

#===(o) ⇒ Object



216
# File 'lib/numru/gphys/unumeric.rb', line 216

def ===(o); o===num; end

#>(o) ⇒ Object



211
# File 'lib/numru/gphys/unumeric.rb', line 211

def >(o); o<num; end

#>=(o) ⇒ Object



213
# File 'lib/numru/gphys/unumeric.rb', line 213

def >=(o); o<=num; end

#numObject



204
# File 'lib/numru/gphys/unumeric.rb', line 204

def num; @num; end