Convert decimal number to rational: Difference between revisions
Convert decimal number to rational (view source)
Revision as of 16:20, 16 November 2023
, 6 months agoadded Ol
m (→{{header|Fōrmulæ}}: minor improvement) |
(added Ol) |
||
Line 1,997:
99/100
909/1000
</pre>
=={{header|Ol}}==
Any number in Ol by default is exact. It means that any number automatically converted into rational form. If you want to use real floating point numbers, use "#i" prefix.
Function `exact` creates exact number (possibly rational) from any inexact.
<syntaxhighlight lang="scheme">
(print (exact #i0.9054054054))
(print (exact #i0.5185185185))
(print (exact #i0.75))
(print (exact #i35.000))
(print (exact #i35.001))
(print (exact #i0.9))
(print (exact #i0.99))
(print (exact #i0.909))
</syntaxhighlight>
{{out}}
<pre>
4077583446378673/4503599627370496
4670399613402603/9007199254740992
3/4
35
4925952829924835/140737488355328
8106479329266893/9007199254740992
4458563631096791/4503599627370496
4093772061279781/4503599627370496
</pre>
|