rubysolo/dentaku

Dentaku::AST::Subtraction requires numeric operands, but got integer

Nghi93 opened this issue · 4 comments

calculator = Dentaku::Calculator.new

calculator.add_function(:custom, :integer, lambda do
  1
end)

calculator.solve(
  a: "1",
  b: "CUSTOM() - a"
)

procudes the error mentioned in the title.

Quickfix is

calculator.add_function(:custom, :numeric, lambda do
  1
end)

Fixed in 475a9e7, thanks!

Thank you for fixing this bug so fast.
Could you create a patch release, please?

just a quick question:
There are other descendants of numerics:

Numeric.descendants
=> [ActiveSupport::Duration::Scalar, Date::Infinity, BigDecimal, Integer, Float, Rational, Complex]

Do you need to support them as well? (at least bigDecimal, Float, Rational and Complex?)

calculator = Dentaku::Calculator.new

calculator.add_function(:custom, :big_decimal, lambda do
  BigDecimal.new("1.23")
end)

calculator.solve(
  a: "1",
  c: "CUSTOM() - a",
)