<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="292130" data-post-id="292130">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jhogberg" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jhogberg/120/24176_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jhogberg
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Erlang Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<blockquote>
<p>But dialyzer has a type system</p>
</blockquote>
<p>Sure, but only if we stretch the definition into uselessness. If we look at <code>dialyzer</code> through the lens of it having a type system, values are lifted to the type level which more or less turns everything into a tautology:</p>
<p>“The type of <code>1</code> is <code>1</code>, the type of <code>:foo</code> is <code>:foo</code>.”<br>
“The return type of <code>bar(1234)</code> is the result of <code>bar(1234)</code>.”<br>
“The argument types for <code>quux/2</code> are those for which it produces a value.”</p>
<p>The latter has funny implications for server loops and other code that doesn’t return normally by design. Oh, and as the type of a value is its value, doesn’t that imply that nearly all functions have dependent types? After all, <code>1 + 2</code> returns <code>3</code> and that’s a type all of its own <img src="https://forum.elixirforum.com/images/emoji/apple/wink.png?v=15" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"></p>
<p>Understanding that <code>dialyzer</code> only reasons about sets of possible values is crucial to working with it.</p>
<blockquote>
<p>For example, if Erlang/Elixir was a statically typed language, maps there would be dependent. When their size is less than 33 items, they use <code>flatmap</code> implementation, while for bigger sizes they use <code>hashmap</code> implementation. So, in this example the type depends on the size of the map</p>
</blockquote>
<p>That detail is hidden and could still be under a dependent type system, perhaps a better example would be <code>list_to_tuple/1</code> where the arity of the tuple depends of the length of the provided list.</p>
<blockquote>
<p>How so? How could I make this work?</p>
</blockquote>
<p>By teaching <code>dialyzer</code> that all numbers can have ranges, not just integers. It should be about as simple as making the integer range logic in <code>lib/dialyzer/erl_types.erl</code> allow any kind of number as lower and upper bound and change all uses to match that. That’s what we do in the Erlang compiler (which has a separate implementation of <code>dialyzer</code>s underlying algorithm) and it works just fine.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="292130" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-typespec-a-float-range-in-elixir/56583/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-292130" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="292130"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="292135" data-post-id="292135">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Fl4m3Ph03n1x" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Fl4m3Ph03n1x/120/11709_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Fl4m3Ph03n1x
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-Erlang-Core-Team" data-username="jhogberg" data-post="12" data-topic="56583">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jhogberg/48/24176_2.png" class="avatar"> jhogberg:</div>
<blockquote>
<p>That detail is hidden and could still be under a dependent type system, perhaps a better example would be <code>list_to_tuple/1</code> where the arity of the tuple depends of the length of the provided list.</p>
</blockquote>
</aside>
<p>Ok, so I understand from this that my example is a subtype of <code>float</code> and not a dependent type.<br>
A clear case of a dependent type would be <code>list_to_tuple/1</code> as you mentioned.</p>
<p>This part is now clear to me.</p>
<aside class="quote group-Erlang-Core-Team" data-username="jhogberg" data-post="12" data-topic="56583">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jhogberg/48/24176_2.png" class="avatar"> jhogberg:</div>
<blockquote>
<p>By teaching <code>dialyzer</code> that all numbers can have ranges, not just integers. It should be about as simple as making the integer range logic in <code>lib/dialyzer/erl_types.erl</code> allow any kind of number as lower and upper bound and change all uses to match that. That’s what we do in the Erlang compiler (which has a separate implementation of <code>dialyzer</code>s underlying algorithm) and it works just fine.</p>
</blockquote>
</aside>
<p>This section however raises several questions. I thought Elixir was compiled to Erlang, which is then compiled into something else.<br>
Shouldn’t then dyalizer know what to do with this?</p>
<p>I feel like I have a knowledge gap in how dialyzer works with Elixir, as I always believed it was the same version for both Elixir and Erlang, and the only “difference” was dialyxir (a wrapper around dialyzer for Elixir).</p>
<p>If Elixir and Erlang use different versions of dialyzer, where can I find them?<br>
If this is the case, why hasn’t Elixir updated its version to that of Erlang in order to support this? (what is the hold-back)</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="292135" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-typespec-a-float-range-in-elixir/56583/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-292135" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="292135"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="292140" data-post-id="292140">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jhogberg" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jhogberg/120/24176_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jhogberg
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Erlang Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><code>dialyzer</code> doesn’t know how to do this for Erlang either. The Erlang compiler has a separate implementation of <em>the same underlying idea as <code>dialyzer</code></em> that it uses for optimizing code, which is capable of handling float ranges.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="292140" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-typespec-a-float-range-in-elixir/56583/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-292140" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="292140"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="292143" data-post-id="292143">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Fl4m3Ph03n1x" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Fl4m3Ph03n1x/120/11709_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Fl4m3Ph03n1x
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-Erlang-Core-Team" data-username="jhogberg" data-post="14" data-topic="56583" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jhogberg/48/24176_2.png" class="avatar"> jhogberg:</div>
<blockquote>
<p><code>dialyzer</code> doesn’t know how to do this for Erlang either. The Erlang compiler has a separate implementation of <em>the same underlying idea as <code>dialyzer</code></em> that it uses for optimizing code, which is capable of handling float ranges.</p>
</blockquote>
</aside>
<p>Alright, so if the Erlang compiler has this functionality implemented, why doesn’t dialyzer have it? This would then benefit the entire BEAM ecosystem if such a change were to occur correct?</p>
<p>Surely there must be a strong reason for this!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="292143" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-typespec-a-float-range-in-elixir/56583/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-292143" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="292143"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="292144" data-post-id="292144">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jhogberg" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jhogberg/120/24176_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jhogberg
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Erlang Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Fl4m3Ph03n1x" data-post="15" data-topic="56583">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fl4m3ph03n1x/48/11709_2.png" class="avatar"> Fl4m3Ph03n1x:</div>
<blockquote>
<p>Alright, so if the Erlang compiler has this functionality implemented, why doesn’t dialyzer have it? This would then benefit the entire BEAM ecosystem if such a change were to occur correct?</p>
<p>Surely there must be a strong reason for this!</p>
</blockquote>
</aside>
<p>No one has cared enough to do it, I’m guessing it’s because few people need these kinds of ranges. The compiler has it to be better at optimizing arithmetic, and the whole BEAM ecosystem does benefit from that. <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>(As an aside, the compiler doesn’t look at <code>@type</code> annotations at all. It only reasons about the code.)</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="292144" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-typespec-a-float-range-in-elixir/56583/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-292144" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="292144"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="292152" data-post-id="292152">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Fl4m3Ph03n1x" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Fl4m3Ph03n1x/120/11709_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Fl4m3Ph03n1x
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-Erlang-Core-Team" data-username="jhogberg" data-post="16" data-topic="56583">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jhogberg/48/24176_2.png" class="avatar"> jhogberg:</div>
<blockquote>
<p>No one has cared enough to do it, I’m guessing it’s because few people need these kinds of ranges.</p>
</blockquote>
</aside>
<p>Alright, thanks for all the info!<br>
What would be the proper channel to raise this as a ticket/request?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="292152" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-typespec-a-float-range-in-elixir/56583/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-292152" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="292152"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="292162" data-post-id="292162">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jhogberg" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jhogberg/120/24176_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jhogberg
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Erlang Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="onebox allowlistedgeneric" data-onebox-src="https://github.com/erlang/otp/issues">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" alt="" width="32" height="32">

      <a href="https://github.com/erlang/otp/issues" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/344;"><img src="https://opengraph.githubassets.com/1e4a6d1a19a29459bd4cb760f55f6f843d9870e5af0190a1b1dfc33ce5a560b1/erlang/otp" class="thumbnail" alt="" width="690" height="345"></div>

<h3><a href="https://github.com/erlang/otp/issues" target="_blank" rel="noopener nofollow ugc">Issues · erlang/otp</a></h3>

  <p>Erlang/OTP. Contribute to erlang/otp development by creating an account on GitHub.</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="292162" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-typespec-a-float-range-in-elixir/56583/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-292162" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="292162"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #17"></div>
  </section>
</div>
    <div class="postbit" id="292194" data-post-id="292194">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="hst337" data-post="11" data-topic="56583">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/h/41988e/48.png" class="avatar"> hst337:</div>
<blockquote>
<p>No, dependent type is a type which <strong>depends on the value</strong></p>
</blockquote>
</aside>
<p>To be more precise, a dependent type is when you can express a quantifier over a value. For example, you can have a type that is represented by all vectors with length of 3.</p>
<p>What typespecs have is singleton types. Those are types that contain a single entry, like the atom <code>:foo</code>, and in our case the type perfectly mirrors a value.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="292194" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-typespec-a-float-range-in-elixir/56583/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-292194" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="292194"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #18"></div>
  </section>
</div>
    <div class="postbit" id="292197" data-post-id="292197">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="hst337" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  hst337
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yes, that’s true. I just didn’t want to dig into formal discussion, and I’ve just provided an example to explain the difference between dependent and independent typing</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="292197" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-typespec-a-float-range-in-elixir/56583/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-292197" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="292197"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #19"></div>
  </section>
</div>
    <div class="postbit" id="292213" data-post-id="292213">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="dimitarvp" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dimitarvp/120/38664_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  dimitarvp
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Fl4m3Ph03n1x" data-post="5" data-topic="56583">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fl4m3ph03n1x/48/11709_2.png" class="avatar"> Fl4m3Ph03n1x:</div>
<blockquote>
<p>I decided to use <code>float</code> and <code>guards</code> in the function. It is not the ideal situation, but its better than having no checks at all.</p>
</blockquote>
</aside>
<p>Exactly what I did, and what a funny coincidence that I just had to code something super similar in the last two days:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  @type double :: float()

  @double_min -1.7976931348623157e308
  @double_max 1.7976931348623157e308

  defguard is_double(x) when is_float(x) and x &gt;= @double_min and x &lt;= @double_max

  @spec do_stuff(double()) :: nil
  def do_stuff(x) when is_double(x) do
    dec = Decimal.from_float(x)
    if Decimal.compare(dec, @decimal_double_min) != :lt and
         Decimal.compare(dec, @decimal_double_max) != :gt do
      # the float is in range, let's do stuff!
    else
      # out of bounds, report error.
    end

    # do something else and return.
    nil
  end
</code></pre>
<p>As you said, it’s definitely better than nothing. Basically everything except the typespec itself is covered. I am nervous about using <code>&gt;=</code> and <code>&lt;=</code> in the guard but my tests have shown that the comparisons are stable for these boundary values .</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="292213" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-typespec-a-float-range-in-elixir/56583/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-292213" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="292213"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>