Arithmetic/Integer: Difference between revisions

Added LFE example
(+ МК-61)
(Added LFE example)
Line 1,088:
{{VI snippet}}<br/>
[[File:LabVIEW_Arithmetic_Integer.png]]
 
=={{header|LFE}}==
 
<lang lisp>
(defmodule arith
(export all))
 
(defun demo-arith ()
(case (: io fread '"Please enter two integers: " '"~d~d")
((tuple 'ok (a b))
(: io format '"~p + ~p = ~p~n" (list a b (+ a b)))
(: io format '"~p - ~p = ~p~n" (list a b (- a b)))
(: io format '"~p * ~p = ~p~n" (list a b (* a b)))
(: io format '"~p^~p = ~p~n" (list a b (: math pow a b)))
; div truncates towards zero
(: io format '"~p div ~p = ~p~n" (list a b (div a b)))
; rem's result takes the same sign as the first operand
(: io format '"~p rem ~p = ~p~n" (list a b (rem a b))))))
</lang>
 
Usage from the LFE REPL:
<lang lisp>
> (slurp '"arith.lfe")
#(ok arith)
> (demo-arith)
Please enter two integers: 2 8
2 + 8 = 10
2 - 8 = -6
2 * 8 = 16
2^8 = 256.0
2 div 8 = 0
2 rem 8 = 2
ok
</lang>
 
=={{header|Liberty BASIC}}==
Note that raising to a power can display very large integers without going to approximate power-of-ten notation.
Anonymous user