Sha256: f036f261c71d0c7ac503a08920660d1081d4387f6c03ce6db0816b797937f7ed
Contents?: true
Size: 1.02 KB
Versions: 2
Compression:
Stored size: 1.02 KB
Contents
require 'dydx' include Dydx module Qlang module Iq class Dydx::Algebra::Formula # FIX: def to_q str = to_s.gsub(/\*\*/, '^').rm(' * ') str.equalize! end end def self.execute(code) ruby_code = Q.to_ruby.compile(code.encode('utf-8')) ruby_obj = eval(ruby_code) optimize_output(ruby_obj).encode('utf-8') rescue SyntaxError # TODO: emergency case ruby_code when /(\d)+(\w)/ execute("#{$1} * #{$2}") end end def self.optimize_output(ruby_obj) case ruby_obj when Matrix, Vector, Dydx::Algebra::Formula ruby_obj.to_q when Numeric # TODO: I know you wanna way.. if ruby_obj > 10000.0 then 'oo' elsif ruby_obj < -10000.0 then '-oo' elsif ruby_obj.abs < Float::EPSILON then '0.0' else ruby_obj.to_s.equalize! end else str = ruby_obj.to_s str.equalize! end end end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
hilbert-0.0.2700000 | lib/qlang/iq.rb |
qlang-0.0.27182124 | lib/qlang/iq.rb |