Arithmetic/Integer: Difference between revisions

Content added Content deleted
(→‎{{header|REXX}}: added a comment to the REXX section header.)
Line 2,194: Line 2,194:
Note that <code>div</code> doesn't always do integer division; it performs the operation "most appropriate to the
Note that <code>div</code> doesn't always do integer division; it performs the operation "most appropriate to the
operand types". [http://perlcabal.org/syn/S03.html#line_729 Synopsis 3] guarantees that <code>div</code> "on built-in integer types is equivalent to taking the floor of a real division". If you want integer division with other types, say <code>floor($a/$b)</code>.
operand types". [http://perlcabal.org/syn/S03.html#line_729 Synopsis 3] guarantees that <code>div</code> "on built-in integer types is equivalent to taking the floor of a real division". If you want integer division with other types, say <code>floor($a/$b)</code>.

=={{header|Phix}}==
<lang Phix>integer a = floor(prompt_number("a = ",{}))
integer b = floor(prompt_number("b = ",{}))

printf(1,"a + b = %d\n", a+b)
printf(1,"a - b = %d\n", a-b)
printf(1,"a * b = %d\n", a*b)
printf(1,"a / b = %g\n", a/b) -- does not truncate
printf(1,"remainder(a,b) = %d\n", remainder(a,b)) -- same sign as first operand
printf(1,"power(a,b) = %g\n", power(a,b))</lang>
{{out}}
<pre>
a = 2
b = 3
a + b = 5
a - b = -1
a * b = 6
a / b = 0.666667
remainder(a,b) = 2
power(a,b) = 8
</pre>


=={{header|PHL}}==
=={{header|PHL}}==