<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged mod</title>
<link>https://ask.clojure.org/index.php/tag/mod</link>
<description></description>
<item>
<title>Incorrect `rem` behavior between clojure.lang.BigInt, Double</title>
<link>https://ask.clojure.org/index.php/10231/incorrect-rem-behavior-between-clojure-lang-bigint-double</link>
<description>&lt;p&gt;This is related to &lt;a rel=&quot;nofollow&quot; href=&quot;https://ask.clojure.org/index.php/1555/bug-in-clojure-core-mod-with-large-double-argument&quot;&gt;issue 1555&lt;/a&gt;, but the types at play are different, so the underlying problem might be different too.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;rem&lt;/code&gt;  seems to be returning very incorrect results between bigint and float. Note the large difference in using &lt;code&gt;10000&lt;/code&gt; as the divisor vs &lt;code&gt;1e4&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user&amp;gt; (rem 9037601485536036300227801N 10000)
7801N
user&amp;gt; (long (rem 9037601485536036300227801N 1e4))
1073741824
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;test.check&lt;/code&gt; provides a tighter example of clearly incorrect results:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user&amp;gt; (rem 9007199254740993N 2)
1N
user&amp;gt; (rem 9007199254740993N 2.0)
0.0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here's a generative test to reproduce this result:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(clojure.test.check/quick-check
 100 (prop/for-all [l gen/size-bounded-bigint
                    r (gen/fmap inc gen/nat)]
                   (== (rem l (double r))
                       (rem l (long r)))))
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10231/incorrect-rem-behavior-between-clojure-lang-bigint-double</guid>
<pubDate>Mon, 22 Feb 2021 15:51:53 +0000</pubDate>
</item>
</channel>
</rss>