SanskritNumbers.fsp - Frink Server Pages highlighter

[Try SanskritNumbers.fsp]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<HTML LANG="en">
 <HEAD>
  <TITLE>Sanskrit Number Converter</TITLE>
  <META HTTP-EQUIV="Default-Style" CONTENT="APE Airy"> 
  <LINK REL="StyleSheet" HREF="/frinkdocs/apeairy.css" TYPE="text/css"
        TITLE="APE Airy"> 
  <LINK REL="Alternate StyleSheet" HREF="/frinkdocs/spaceship.css"
        TYPE="text/css" TITLE="Spaceship">
  <LINK REL="Alternate StyleSheet" HREF="/frinkdocs/style.css" TYPE="text/css"
        TITLE="APE Classic">
  <LINK REL="Alternate StyleSheet" HREF="/frinkdocs/style2.css" TYPE="text/css"
        TITLE="Compact"> 
  <LINK REL="icon" HREF="/images/futureboyicon.png" TYPE="image/png">
  <META NAME="viewport" CONTENT="width=device-width, initial-scale=1.0">
 </HEAD>

 <BODY onLoad="ans.focus()">
 <% use ../IndianAstronomy.frink %>
  <H1>Sanskrit Number Converter</H1>

  <A NAME="S2D"><H2>Sanskrit to Decimal</H2></A>
  <P>
   Enter Sanskrit numbers in the form &#x0967;&#x096A;&#x0964;&#x0967;&#x0968;&#x0964;&#x0967;&#x0969; using the buttons below or in the Neugebauer form
   (e.g. 14;12,13).
  </P>
  <%
     if n
     {
       dev = numberToDevanagari[n]
       neu = DevanagariToNeugebauer[dev]
       equiv = parseDevanagariFraction[dev]
       ne = equiv div 1
       fe = equiv - ne
       dequiv = 1.0 equiv
       println["<DIV CLASS=\"back\">"]
       println["""<P>
        <SPAN STYLE="font-size:x-large">$dev<BR>$neu</SPAN>
       </P>"""]

       if (fe != 0)
          println["""<P><SPAN STYLE="font-size:large">&nbsp;&nbsp;&nbsp;= $ne + $fe</SPAN></P>"""]
       println["""<P><SPAN STYLE="font-size:large">&nbsp;&nbsp;&nbsp;= $dequiv</SPAN></P>"""]
       println["""<P><SPAN STYLE="font-size:large">&nbsp;&nbsp;&nbsp;= $equiv</SPAN></P>"""]
       println["</DIV>"]
    }
  %>

  <FORM METHOD="POST" ACTION="SanskritNumbers.fsp#S2D">
  <P>
    Number:<BR>
    <INPUT TYPE="TEXT" NAME="n" ID="n"><BR>
    <INPUT TYPE="BUTTON" VALUE="&#x0966; : 0" onClick="inf.value=inf.value+'\u0966'">
    <INPUT TYPE="BUTTON" VALUE="&#x0967; : 1" onClick="inf.value=inf.value+'\u0967'">
    <INPUT TYPE="BUTTON" VALUE="&#x0968; : 2" onClick="inf.value=inf.value+'\u0968'">
    <INPUT TYPE="BUTTON" VALUE="&#x0969; : 3" onClick="inf.value=inf.value+'\u0969'">
    <INPUT TYPE="BUTTON" VALUE="&#x096a; : 4" onClick="inf.value=inf.value+'\u096a'">
    <INPUT TYPE="BUTTON" VALUE="&#x096b; : 5" onClick="inf.value=inf.value+'\u096b'">
    <INPUT TYPE="BUTTON" VALUE="&#x096c; : 6" onClick="inf.value=inf.value+'\u096c'">
    <INPUT TYPE="BUTTON" VALUE="&#x096d; : 7" onClick="inf.value=inf.value+'\u096d'">
    <INPUT TYPE="BUTTON" VALUE="&#x096e; : 8" onClick="inf.value=inf.value+'\u096e'">
    <INPUT TYPE="BUTTON" VALUE="&#x096f; : 9" onClick="inf.value=inf.value+'\u096f'">
    &nbsp;
    <INPUT TYPE="BUTTON" VALUE="&#x0964;" onClick="inf.value=inf.value+'\u0964'">
    <BR>
    <INPUT TYPE="SUBMIT" VALUE="Convert">
   </P>

  </FORM>

  <A NAME="D2S"><H2>Decimal to Sanskrit</H2></A>
  <P>
   Enter a decimal number or fraction in the form 1.234, or 1/45, 1+1/2, or
   (equivalently,) 1 1/2.  In fact, since this is powered by <A HREF="/frinkdocs/">Frink</A>, you can enter any
    mathematical expression including dimensionless constants like "pi" or "e".
  </P>
  <% if digits
     {
        td = trim[digits]
        if td =~ %r/\d+/
           digits = parseInt[td]
        else
           digits = 8
     } else
        digits = 8
        
     if dec
     {
        dec =~ %s/(\d+)\s+(\d+)/$1+$2/
        num = eval[dec]
        nstr = sexagesimal[num, digits]
        dstr = numberToDevanagari[nstr]
        reconv = parseDevanagariFraction[dstr]
        err = abs[num - reconv]
       println["<DIV CLASS=\"back\">"]
       println["""<P><SPAN STYLE="font-size:large">$dec =</SPAN></P>
        <P><SPAN STYLE="font-size:x-large">&nbsp;&nbsp;$nstr</SPAN> (Neugebauer form)<BR>
        <SPAN STYLE="font-size:x-large">&nbsp;&nbsp;$dstr</SPAN> (Devanagari form)</P>"""]
        if (err == 0)
           println["<P>(result is exact.)</P>"]
        else
           println["<P>Error = $err due to truncation to $digits digits.</P>"]
       println["</DIV>"]
     }
  %>

  <FORM METHOD="POST" ACTION="SanskritNumbers.fsp#D2S" NAME="f2">
  <P>
   Number: <INPUT TYPE="TEXT" NAME="dec" ID="dec">
   Max. sexagesimal digits: <INPUT TYPE="TEXT" NAME="digits" SIZE="2" VALUE="$digits"><BR>
   <INPUT TYPE="SUBMIT" VALUE="Convert">
  </P>
  </FORM>

  <SCRIPT TYPE="text/javascript">
    var ans = document.getElementById("<%= dec ? "dec" : "n" %>");
    var inf = document.getElementById("n");
    ans.focus();
  </SCRIPT>

  <HR>
  <P>
   <I>Comments or questions to <A HREF="mailto:eliasen@mindspring.com">Alan Eliasen</A></I>.
  </P>

  <P>
   <A HREF="highlight.fsp?f=SanskritNumbers.fsp">View Source</A>
  </P>

  <P>
   Back to <A HREF="/frinkdocs/fspdocs.html">Frink Server Pages
    documentation.</A>
  </P>  
 </BODY>
</HTML>

[Try SanskritNumbers.fsp]


Alan Eliasen was born 17596 days, 22 hours, 2 minutes ago.

Back to Frink Server Pages documentation.