Sha256: 16d5c9b31faa7fe8738f2cd4c6e3c80c5d0808d613f3059b687fcff4b67a5026

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

module TfPoint
  module Calculate
  	##+  排序,大的在前,小的在后,如果是最后一次(n=2),不加括号
    def plus_operation(expa, expb, n, numa, numb)
      return "", 0 if !numa.is_a?(Fixnum) || !numb.is_a?(Fixnum)
    	expa, expb = expb, expa if expa.is_num? && expb.is_num? && expa < expb
    	exp = (n == 2) ? expa + '+' + expb : '(' + expa + '+' + expb + ')'
      return exp, (numa + numb)
    end

    ##-
    def sub_operation(expa, expb, n, numa, numb)
      return "", 0 if !numa.is_a?(Fixnum) || !numb.is_a?(Fixnum)
    	exp = (n == 2) ? expa + '-' + expb : '(' + expa + '-' + expb + ')'
      return exp, (numa - numb)
    end

    ##*
    def multi_operation(expa, expb, numa, numb)
      return "", 0 if !numa.is_a?(Fixnum) || !numb.is_a?(Fixnum)
    	exp = (expa > expb) ? expa + '*' + expb : expb + '*' + expa
      return exp, (numa * numb)
    end

    #/
    def devision_operation(expa, expb, numa, numb)
      return "", 0 if !numa.is_a?(Fixnum) || !numb.is_a?(Fixnum)
      exp = expa + '/' + expb
      return exp, (numa / numb)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
24point-0.0.2 lib/24point/calculate.rb
24point-0.0.1 lib/24point/calculate.rb