<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged bigint</title>
<link>https://ask.clojure.org/index.php/tag/bigint</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>
<item>
<title>Why do BigInt literals not require N suffix, but BigDecimals do?</title>
<link>https://ask.clojure.org/index.php/8510/why-do-bigint-literals-not-require-suffix-but-bigdecimals-do</link>
<description>&lt;p&gt;I find it a bit inconsistent that I can type:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;123423534634544234534634645342363462443649886756676645466767687
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And it will auto-promote it to a BigInt to fit, without me needing to specify so with the N suffix.&lt;/p&gt;
&lt;p&gt;But if using decimal:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;12.3423534634544234534634645342363462443649886756676645466767687
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It won't auto-promote to BigDecimal without explicitly adding an M suffix. Instead it'll truncate to double precision. &lt;/p&gt;
&lt;p&gt;Any reason why that is?&lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/8510/why-do-bigint-literals-not-require-suffix-but-bigdecimals-do</guid>
<pubDate>Tue, 03 Sep 2019 19:28:00 +0000</pubDate>
</item>
</channel>
</rss>