 convert/rational - Maple Programming Help

Home : Support : Online Help : Programming : Data Types : Conversion : convert/rational

convert/rational

convert float to an approximate rational

 Calling Sequence convert(float, rational, digits) convert(float, fraction, digits)

Parameters

 float - floating-point number digits - (optional) integer or the name exact

Description

 • The convert/rational function converts a floating-point number to an approximate rational number. The meaning of the type fraction is identical with rational in this context.
 • The accuracy of the conversion will depend on the value of the global variable Digits, or the value of digits if specified as an integer.
 • If the third argument digits is the name 'exact' then an exact conversion of float to a rational will be performed; thus Float(f, e) becomes simply f*10^e. Note that exact conversion executes much more quickly than the more sophisticated conversion.
 Note: See also the identify command to find a closed form for a decimal approximation of a number.

Examples

 > convert(0.125,rational);
 $\frac{{1}}{{8}}$ (1)
 > convert(2.345,rational);
 $\frac{{469}}{{200}}$ (2)
 > convert(0.3333333333,rational);
 $\frac{{1}}{{3}}$ (3)
 > convert(0.3333333333,rational,exact);
 $\frac{{3333333333}}{{10000000000}}$ (4)
 > convert(evalf(Pi),rational);
 $\frac{{104348}}{{33215}}$ (5)
 > convert(evalf(Pi),rational,3);
 $\frac{{22}}{{7}}$ (6)
 > convert(evalf(Pi),rational,exact);
 $\frac{{1570796327}}{{500000000}}$ (7)