Convert decimal number to rational: Difference between revisions

actually, 42/81 is exactly reducible to 14/27. And update Julia
(change intro, hopefully clearer; add Julia)
(actually, 42/81 is exactly reducible to 14/27. And update Julia)
Line 7:
Because of this, the following fractions cannot be obtained (reliably) unless the language has some way of representing repeating decimals:
* 67 / 74 = 0.9(054) = 0.9054054...
* 4214 / 8127 = 0.(518) = 0.518518...
* 3 / 4 = 0.75
 
Line 654:
259259//500000
3//4
 
Since Julia by default uses its [[wp:Double-precision floating-point format#IEEE 754 double-precision binary floating-point format: binary64|Float64]] type to represent floating-point numbers, if enough decimal digits are provided (so that the difference between the floating-point representation of the resulting fraction and the original number is smaller than the machine epsilon) the smaller fraction is returned, which in this case is the exact result:
 
julia> rational(0.5185185185185185)
14//27
julia> rational(0.9054054054054054)
67//74
 
If the difference becomes smaller than
 
=={{header|Mathematica}}==
Anonymous user