View Source Ratio.FloatConversion (ratio v3.0.2)
Link to this section Summary
Functions
Converts a float to a rational number. Because base-2 floats cannot represent all base-10 fractions properly, the results might be different from what you might expect. See The Perils of Floating Point for more information about this.
Link to this section Functions
Converts a float to a rational number. Because base-2 floats cannot represent all base-10 fractions properly, the results might be different from what you might expect. See The Perils of Floating Point for more information about this.
examples
Examples
iex> Ratio.FloatConversion.float_to_rational(10.0)
10 <|> 1
iex> Ratio.FloatConversion.float_to_rational(13.5)
27 <|> 2
iex> Ratio.FloatConversion.float_to_rational(1.1)
2476979795053773 <|> 2251799813685248