ruby - What does the quo method do? -
consider following methods, found in byar gem:
## # calculate lower boundary observed cases def self.lower_bound(obs, z_value = z_value) return 0 if obs == 0 obs * (1 - 1.quo(9 * obs) - z_value.quo(3 * math.sqrt(obs))) ** 3 end ## # calculate upper boundary observed cases def self.upper_bound(obs, z_value = z_value) obs = obs + 1 obs * (1 - 1.quo(9 * obs) + z_value.quo(3 * math.sqrt(obs))) ** 3 end
i port these methods javascript, unsure quo
does.
quo
method defined on numeric
class (and redefined in float
class), calculates quotient of receiver given argument. in other words, x.quo(y)
equivalent x / y
, more precise.
the difference here comes in when x
, y
fixnum
s (ie. integer value):
> (1 / 2) => 0 > (1 / 2).class => fixnum > 1.quo(2) => (1/2) > 1.quo(2).class => rational > 1.quo(2.5) => 0.4 > 1.quo(2.5).class => float
basically, quo
ensures result of division expressed accurately returing rational
or float
, depending on receiver , argument.
in javascript, there isn't distinction between different types of numbers, , division returns floating point number if necessary, first method can expressed as:
obs * math.pow(1 - 1 / (9 * obs) - z_value / (3 * math.sqrt(obs)), 3)
Comments
Post a Comment