Math functions on float32s?

agolangf · · 387 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>In a library I&#39;m currently working on I use a lot of functions from the math package, which as far as I can tell are all defined for float64s, and so many of my types / functions use float64s. </p> <p>However, it would be really nice to be able to do a find/replace in my project and change everything over to float32 for space reasons. But I seem prevented from doing this because of the cases where I need to use those functions from the math package (Sqrt, Pow, Exp, Log mostly).</p> <p>Does anyone have any suggestions for what I can do? Casting seems like it would get messy with casting from a higher precision to a lower precision. It&#39;d be nice if the math package had float32 versions for all its functions.</p> <hr/>**评论:**<br/><br/>recurrency: <pre><p><a href="/u/chewxy" rel="nofollow">/u/chewxy</a> got you covered. </p> <p><a href="https://github.com/chewxy/math32" rel="nofollow">https://github.com/chewxy/math32</a></p></pre>ConfuciusBateman: <pre><p>Wow. Beautiful, for some reason I didn&#39;t come across this in looking for a solution. Thanks a lot!</p></pre>chewxy: <pre><p>Hey. lmk if I can help you in any way. </p></pre>ConfuciusBateman: <pre><p>Definitely will do, thank you.</p></pre>chewxy: <pre><p>protip - if your entire lib is in float32:</p> <pre><code> import math &#34;github.com/chewxy/math32&#34; </code></pre> <p>Then you won&#39;t need to find and replace</p></pre>ConfuciusBateman: <pre><p>Unfortunately it&#39;s all float64 right now, so I&#39;ll still need to find and replace right? </p></pre>Redundancy_: <pre><p>&#34;for space reasons&#34; - is there a reason that you think that&#39;s going to be an important consideration?</p></pre>ConfuciusBateman: <pre><p>A lot of these floats are getting communicated over a network at a time, so reducing the space that a single float takes up would help in that regard. </p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

387 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传