#+title: RPN calculator for multi-precision finite arithmetic * Task[fn:1] Create a calculator for multi-precision finite arithmetic (8 digits) for four operations (​+, -, *, ÷) based on single-precision finite arithmetic, where the "​+​1" rule is defined and the properties of commutativity (​+, *), associativity (​+, *), and distributivity of * over + are satisfied; an additive identity "a" and a multiplicative identity "b" are defined; and the following property holds: for (∀x) x*a=a. Additionally, you can implement exponentiation, as well as the search for GCD and LCM for two numbers. #+caption: The "+1" rule #+attr_html: :style margin: auto; | x | = | a | b | c | d | e | f | g | h | | x + b | = | b | d | h | c | f | a | e | g | * Documentation The exported report can be found at [[https://git.michalec.dev/uni/term-03/discrete-math/coursework/report.pdf][this link]]. * Showcase #+begin_src text > jsadh [-] ERROR: input doesn't match regexp `^\s*([+-][a-h]{1,8}|nop|dup|del|clr|swp|neg|add|mul|sub|div|mod|inc|dec|pow|gcd|lcm)\s*$' > nop > +f f > f f > dup f f f > add f be > sub -f > neg f > -a f a > div [*] INFO: division by zero [*] INFO: operation resulted in empty set > +a a > a a > div [*] INFO: dividing zero by zero [*] INFO: operation result is a range: [-ffffffff; ffffffff] > +ffffffff ffffffff > ffffffff ffffffff > mul [-] ERROR: operation has overflown > +ghf ghf > -fe ghf -fe > mod eb > +ghf eb ghf > -fe eb ghf -fe > div eb -g > -fe eb -g -fe > mul eb hee > add ghf > inc gga > ggb > ggd > ggc > dec ggd > ggb > gga > del > [*] INFO: stack is already empty > clr [*] INFO: stack is already empty > +d d > +h d h > pow da > del > +e e > +h e h > gcd d > +c d c > lcm e > +f e f > swp f e > clr > ^Cinterrupt #+end_src * Unlicense #+include: UNLICENSE verse * Footnotes [fn:1] Original text: #+html: #+begin_quote Сформировать калькулятор «большой» конечной арифметики (8 разрядов) для четырех действий (​+, -, *, ÷)= на основе «малой» конечной арифметики, где задано правило «+1» и выполняются свойства коммутативности (​+, *), ассоциативности (​+, *), дистрибутивности * относительно +, заданы аддитивная единица «a» и мультипликативная единица «b», а также выполняется свойство: для (∀х) х*a=a. Дополнительно можно реализовать возведение в степень, поиск НОД и НОК для двух чисел. #+caption: Правило «+1»: #+attr_html: :style margin: auto; | x | = | a | b | c | d | e | f | g | h | | x + b | = | b | d | h | c | f | a | e | g | #+end_quote #+html: