Blame | Last modification | View Log | RSS feed
!goto $wims_read_parm
:def
title=Convert to fraction
synonyme=fraction
input=function
!exit
:proc
t=!varlist nofn $formula
!for v in $t
s=!charcnt $v
!if $s=1 and $v!=e
error=bad_formula
!exit
!endif
!next v
pari_precision=50
result=!exec pari d=contfracpnqn(contfrac($formula)); print(d[1,1])\
print(d[2,1])\
print(d[1,2])\
print(d[2,2])\
print(abs(d[1,1]/d[1,2]-$formula))\
print(d[2,1]/d[2,2])
!distribute lines $result into n1,d1,n2,d2,diff,ratio
!exit
:output
<table border=0 cellspan=0 cellspacing=0>
!if $diff>0 and $ratio>10
<tr><td nowrap rowspan=3>
!htmlmath $formula
=
<td align=center>$n1</td>
<td nowrap rowspan=3> $m_approx
<td align=center>$n2</td><td rowspan=3> .
<tr><td nowrap><hr size=2 noshade></td><td nowrap><hr size=2 noshade></td>
<tr><td align=center>$d1</td><td align=center>$d2</td>
!else
<tr><td nowrap rowspan=3>
!htmlmath $formula
=
<td align=center>$n1</td>
<td rowspan=3> .
<tr><td nowrap><hr size=2 noshade></td>
<tr><td align=center>$d1</td>
!endif
</table>
!exit