Metallic ratios: Difference between revisions

Content added Content deleted
(Added a Ruby implementation.)
m (Ruby 3.1 changed "/".)
Line 1,677: Line 1,677:
when 1
when 1
xn1 = BigDecimal(xn)
xn1 = BigDecimal(xn)
prev = (xn1 / xn2).round(precision)
prev = xn1.div(xn2, 2 * precision).round(precision)
else
else
xn2, xn1 = xn1, BigDecimal(xn)
xn2, xn1 = xn1, BigDecimal(xn)
this = (xn1 / xn2).round(precision)
this = xn1.div(xn2, 2 * precision).round(precision)
return Struct.new(:ratio, :terms).new(prev, inx - 1) if prev == this
return Struct.new(:ratio, :terms).new(prev, inx - 1) if prev == this
prev = this
prev = this