Last active
August 29, 2015 14:23
-
-
Save dohyunkim/e76163fe169aceae5058 to your computer and use it in GitHub Desktop.
MetaPost as a math calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \input luamplib.sty | |
| \def\mpcalc#1#2#3{% #1 control sequence | |
| % #2 math formular | |
| % #3 precision ( <= 1000 ) | |
| \begingroup | |
| \setbox0\hbox{% | |
| \mplibnumbersystem{decimal}% | |
| \mplibcode | |
| numberprecision := #3; | |
| VerbatimTeX("\gdef#1{" & decimal (#2) & "}"); | |
| beginfig(0); draw origin; endfig; | |
| \endmplibcode | |
| }% | |
| \endgroup | |
| } | |
| \def\digitsv#1{% | |
| \count255=0 \expandafter\digitsV#1\end | |
| } | |
| \def\digitsV#1{% | |
| \ifx#1\end | |
| \else | |
| #1% | |
| \ifx.#1% | |
| \count255=1 | |
| \else | |
| \ifnum\count255 > 0 | |
| \ifdim\dimexpr\count255 pt/ 5 * 5\relax = \count255 pt | |
| \space | |
| \fi | |
| \advance\count255 by 1 | |
| \fi | |
| \fi | |
| \expandafter\digitsV | |
| \fi | |
| } | |
| \mpcalc{\logtenii} | |
| {(mlog 2) / (mlog 10)} | |
| {1000} | |
| $ \log_{10} 2 = $ \digitsv\logtenii | |
| \end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
result:
log_{10} 2 =0.30102 99956 63981 19521 37388 94724 49302 67681 89881 46210 85413 10427 46112 71081 89274 42450 94869 27252 11818 61720 40684 47719 14309 95379 09476 78811 33523 50599 96923 33704 69557 50645 02964 25419 34026 61819 73431 16029 43501 18390 28981 78582 61715 44395 31861 92904 63538 84699 52023 93108 49612 46254 04002 63312 59462 14788 45847 31828 26726 83982 32619 65427 93507 63131 75483 50927 13896 49469 17785 76891 80507 90007 59954 80878 15459 71458 50319 64877 62612 24922 90829 11819 09514 98997 17161 98604 77676 50006 78205 17912 55732 86286 68342 00040 29205 09837 08457 22248 95494 29756 21497 07244 65970 86136 89609 22190 94827 61214 39149 65282 35167 82649 23148 04027 74624 32441 63311 53873 82593 03883 03938 06332 16130 23905 18805 82131 91568 54616 92905 30150 51319 26985 37848 84187 18320 06575 35694 68392 97174 21320 10905 89689 08505 85624 64098 72183 96876 64853 98562 35161 27730 26389 27878 26084 98366 81030 30843 14155 60813 94361 76745 48856 66342 45381 23733 93242 24695 94349 06021 20445 04296 82746 06884 78546 11568 47684 10643 79795 00465 96991 77456 57540 86401 84640 79456 52954 43410 77408 29399 97454 00737 21701 68019 48890 55485 69106 94003 75411 68996 34157