Разделы › Интересы › Хобби, увлечения

ХОХобби, увлечения

прога на javascript - калькулятор

3 ответа1 участников

Войти, чтобы ответить или подписаться.

+180автор19.08

&lt;title id=&quot;tit&quot;&gt;&lt;/title&gt;\<br/\>&lt;input id=&quot;inp&quot; style=&quot;width:400;font-size:30&quot; onKeyUp=&quot;F()&quot;&gt;&lt;p&gt;\<br/\>&lt;code id=&quot;res&quot; style=&quot;font-size:30&quot;&gt;&lt;/code&gt;&lt;p&gt;\<br/\>&lt;code id=&quot;more&quot;&gt;&lt;/code&gt;\<br/\>&lt;script&gt;\<br/\>var g=\[\],gc,s=inp.value,type,k,i; var rad=90/Math.asin(1),pi=360/rad/2; var \<br/\>pp=String.fromCharCode(13);\<br/\>function T(ch){var e, l,ll, m1=&quot;qwertyuiopasdfghjklzxcvbnm&quot;, m2=&quot;+-\/()&quot;, m3=\<br/\>\[&quot;sin&quot;,&quot;cos&quot;,&quot;tan&quot;,&quot;asin&quot;,&quot;acos&quot;,&quot;atan&quot;,&quot;pi&quot;\];\<br/\>if(ch\1==ch || ch==&quot;.&quot;){e=1};\<br/\>ll=0; for(l=0;l&lt;m1.length;l){if(ch==m1\[l\]){ll=1};}; if(ll==1){e=2};\<br/\>ll=0; for(l=0;l&lt;m2.length;l){if(ch==m2\[l\]){ll=1};}; if(ll==1){e=3};\<br/\>ll=0; for(l=0;l&lt;m3.length;l){if(ch==m3\[l\]){ll=1};}; if(ll==1){e=4};\<br/\>return e;};function H(){var b=-1,bb,jj=0,n,u=\[\];\<br/\>for(gc=0;gc&lt;g.length;gc){if(g\[gc\]==&quot;(&quot;){ if(T(g\[gc+1\])==1 || T(g\[gc+1\])==4){b=gc; };};};\<br/\>if(b&gt;=0){for(gc=b;gc&lt;g.length;gc++){if(g\[gc\]==&quot;)&quot;){bb=gc; gc=g.length;};};\<br/\>for(n=b+1;n&lt;bb;n){u\[jj\]=g\[n\]; jj}; n--; more.innerText=more.innerText+u;};\<br/\>if(b==-1){u=g; more.innerText=more.innerText+u;};\<br/\>for(gc=0;gc&lt;u.length;gc++){\<br/\>if(u\[gc\]==&quot;sin&quot; &amp;&amp; T(u\[gc+1\])==1){u\[gc\]=Math.sin(u\[gc+1\]/rad); u.splice(gc+1,1); gc--};\<br/\>if(u\[gc\]==&quot;cos&quot; &amp;&amp; T(u\[gc+1\])==1){u\[gc\]=Math.cos(u\[gc+1\]/rad); u.splice(gc+1,1); gc--};\<br/\>if(u\[gc\]==&quot;tan&quot; &amp;&amp; T(u\[gc+1\])==1){u\[gc\]=Math.tan(u\[gc+1\]/rad); u.splice(gc+1,1); gc--};\<br/\>if(u\[gc\]==&quot;asin&quot; &amp;&amp; T(u\[gc+1\])==1){u\[gc\]=(Math.asin(u\[gc+1\])\rad); u.splice(gc+1,1); gc--};\<br/\>if(u\[gc\]==&quot;acos&quot; &amp;&amp; T(u\[gc+1\])==1){u\[gc\]=(Math.acos(u\[gc+1\])\rad); u.splice(gc+1,1); gc--};\<br/\>if(u\[gc\]==&quot;atan&quot; &amp;&amp; T(u\[gc+1\])==1){u\[gc\]=(Math.atan(u\[gc+1\])\rad); u.splice(gc+1,1); gc--};};\<br/\>for(gc=0;gc&lt;u.length;gc++){\<br/\>if(T(u\[gc\])==1 &amp;&amp; u\[gc+1\]==&quot;\\&quot; &amp;&amp; T(u\[gc+2\])==1){u\[gc\]=u\[gc\]\\u\[gc+2\]; u.splice(gc+1,2); gc--};\<br/\>if(T(u\[gc\])==1 &amp;&amp; u\[gc+1\]==&quot;\<a target="\_blank" href="//"\>ссылка\</a\> &amp;&amp; T(u\[gc+2\])==1){u\[gc\]=u\[gc\]\\(1/u\[gc+2\]); u.splice(gc+1,2); \<br/\>gc--}};\<br/\>for(gc=0;gc&lt;u.length;gc++){\<br/\>if(T(u\[gc\])==1 &amp;&amp; u\[gc+1\]==&quot;\&quot; &amp;&amp; T(u\[gc+2\])==1){u\[gc\]=u\[gc\]\u\[gc+2\]; u.splice(gc+1,2); gc--};\<br/\>if(T(u\[gc\])==1 &amp;&amp; u\[gc+1\]==&quot;/&quot; &amp;&amp; T(u\[gc+2\])==1){u\[gc\]=u\[gc\]/u\[gc+2\]; u.splice(gc+1,2); gc--}};\<br/\>for(gc=0;gc&lt;u.length;gc++){if(T(u\[gc\])==1 &amp;&amp; u\[gc+1\]==&quot;+&quot; &amp;&amp; T(u\[gc+2\])==1){u\[gc\]=u\[gc\]\1+u\[gc+2\]\1; u.splice(gc+1,2);gc--};\<br/\>if(T(u\[gc\])==1 &amp;&amp; u\[gc+1\]\1&lt;0){u\[gc\]=u\[gc\]\1+u\[gc+1\]; u.splice(gc+1,1); gc--};\<br/\>if(u\[gc\]&lt;0 &amp;&amp; T(u\[gc+1\])==1){u\[gc\]=u\[gc\]\1+u\[gc+1\]; u.splice(gc+1,1); gc--};\<br/\>if(T(u\[gc\])==1 &amp;&amp; u\[gc+1\]==&quot;-&quot; &amp;&amp; T(u\[gc+2\])==1){u\[gc\]=u\[gc\]\1-u\[gc+2\]\1; u.splice(gc+1,2); gc--};\<br/\>};if(u.length==1){if(b&gt;=0 &amp;&amp; bb&gt;b){more.innerText=more.innerText+&quot; = &quot;+u+pp; g\[b\]=u\[0\]; g.splice(b+1,bb-b);};\<br/\>res.innerText=g;};if(b==-1){more.innerText=more.innerText+&quot; = &quot;+u;};};\<br/\>function F(){s=inp.value; more.innerText=&quot;&quot;; res.innerText=&quot;&quot;;\<br/\>if(s.length&gt;0){g.splice(0,g.length-1);type=-1; gc=-1;for(i=0;i&lt;s.length;i){k=T(s\[i\]);\<br/\>if(k\*1==k){if(type!=k || type==3){type=k; gc; g\[gc\]=&quot;&quot;; g\[gc\]=s\[i\];}else{g\[gc\]=g\[gc\]+s\[i\];};\<br/\>};};\<br/\>for(gc=0;gc&lt;g.length;gc++){if(g\[gc\]==&quot;-&quot; &amp;&amp; T(g\[gc+1\])==1){g\[gc\]=0-g\[gc+1\]; g.splice(gc+1,1)}};\<br/\>for(gc=0;gc&lt;g.length;gc++){if(g\[gc\]==&quot;\&quot; &amp;&amp; g\[gc+1\]==&quot;\&quot;){g\[gc\]=&quot;\\&quot;; g.splice(gc+1,1)}};\<br/\>for(gc=0;gc&lt;g.length;gc++){if(g\[gc\]==&quot;/&quot; &amp;&amp; g\[gc+1\]==&quot;/&quot;){g\[gc\]=&quot;\<a target="\_blank" href="//;"\>ссылка\</a\> g.splice(gc+1,1)}};\<br/\>for(gc=0;gc&lt;g.length;gc){if(g\[gc\]==&quot;pi&quot;){g\[gc\]=pi;}};\<br/\>var cc; for(cc=0;cc&lt;10;cc){H(); if(g.length==1){cc=10}}; \<br/\>};};res.innerText=g;&lt;/script&gt;

00
+18019.08

можно полностью задать функцию в строчку, использовать скобки, вложенные скобки
операторы:
sin cos tan asin acos atan pi / + - * //
например sin30 или sin(30) - без разницы
возвести в любую степень: 3**5
взять корень любой степени: 3// 7
синтаксис схож с javascript

00
+18019.08

например, посчитать сопротивление резисторов при параллельном соединении:
1/(1/200+1/500+1/1000) =125
площадь круга:
pi10*2 =314.1592653589793
2 в квадрате в квадрате в квадрате в квадрате:
22222 =65536
корень 12 степени из 2:
2// 12 =1.0594630943592953
(sin30+cos60)+(atan1)*8 =361
(((((sin90)2)3)5)6)**2 =32400

00
+18019.08

Блинская фигня: слово "ссылка" заменить на
// ";
и пробел после косых убрать

00