lib/muflax/math.rb in muflax-0.5.0 vs lib/muflax/math.rb in muflax-0.5.1
- old
+ new
@@ -33,7 +33,25 @@
end
def choose k, n
Math.factorial(n) / (Math.factorial(k) * Math.factorial(n - k))
end
+
+ def mass_index coeff, mass, height, adjustment=1.0
+ h /= 100.0 if (50..300).include? h # cm -> m auto-correction
+ adjustment * (mass / (height ** coeff))
+ end
+
+ def mass_index_at coeff, index, height, adjustment=1.0
+ h /= 100.0 if (50..300).include? h # cm -> m auto-correction
+ index * (height ** coeff) / adjustment
+ end
+
+ def bmi m, h ; mass_index 2.0, m, h ; end
+ def bmi_adj m, h ; mass_index 2.5, m, h, 1.3 ; end
+ def bsi m, h ; mass_index 3.0, m, h ; end
+
+ def bmi_at i, h ; mass_index_at 2.0, i, h ; end
+ def bmi_adj_at i, h ; mass_index_at 2.5, i, h, 1.3 ; end
+ def bsi_at i, h ; mass_index_at 3.0, i, h ; end
end
end