<?xml version="1.0" encoding="windows-1252"?>
<node id="1012834" title="Re: built in function for binary division" created="2013-01-11 04:12:17" updated="2013-01-11 04:12:17">
<type id="11">
note</type>
<author id="634253">
AnomalousMonk</author>
<data>
<field name="doctext">
&lt;p&gt;
[ghosh123]: &lt;br&gt;
In addition the the [id://1012795|reply] of [Kenosis], note also the [doc://integer] pragma. Perl represents numbers internally as doubles. Although the fractional portion of a number is ignored when printed as binary, it still exists and can produce perhaps puzzling results in subsequent calculations. &lt;c&gt; use integer; &lt;/C&gt; causes the fractional portion to be majick'd away (don't ask me for details on this). This may produce results in your 'integer' operations that are more consistent with what you expect. (Note in the examples below, the divisor/multiplier is 0b1110 (14), not 0b1111.)
&lt;/P&gt;

&lt;c&gt;
&gt;perl -wMstrict -le
"my $quo = 0b10010110 / 0b1110;
 my $n   = $quo       * 0b1110;
 printf qq{%f %b;  %f %b \n}, $quo, $quo, $n, $n;
 ;;
 use integer;
 $quo = 0b10010110 / 0b1110;
 $n   = $quo       * 0b1110;
 printf qq{%f %b;  %f %b \n}, $quo, $quo, $n, $n;
"
10.714286 1010;  150.000000 10010110
10.000000 1010;  140.000000 10001100
&lt;/C&gt;
</field>
<field name="root_node">
1012790</field>
<field name="parent_node">
1012790</field>
</data>
</node>
