Sha256: 7c6d6079d56a4dbf92c90b7750f85ef5a4037b1a48c9b7582b4f816a8ed90134
Contents?: true
Size: 1.53 KB
Versions: 3
Compression:
Stored size: 1.53 KB
Contents
#!/usr/bin/env ruby # -*- encoding: utf-8 -*- # Copyright Steffie Dorn <mail@muflax.com>, 2018 # License: GNU APGLv3 (or later) <http://www.gnu.org/copyleft/gpl.html> module Math class << self def harmonic n (1..n).reduce(0.0){|s, i| s + (1.0 / i)} end def zipf k, n 1.0 / (k.to_f * harmonic(n)) end def tolerance total θ = total / Math.log(total) θ > total ? total : θ.round end alias :tolerate :tolerance alias :θ :tolerance # TODO meh iterative solution def sufficiency exceptions n = 1 n += 1 while θ(n) < exceptions n end alias :sufficient :sufficiency def factorial n (2..n).reduce(1){|f, x| f * x} 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 height /= 100.0 if (50..300).include? height # cm -> m auto-correction adjustment * (mass / (height ** coeff)) end def mass_index_at coeff, index, height, adjustment=1.0 height /= 100.0 if (50..300).include? height # 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
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
muflax-0.5.5 | lib/muflax/math.rb |
muflax-0.5.3 | lib/muflax/math.rb |
muflax-0.5.2 | lib/muflax/math.rb |