<p>In a library I'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'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'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 "github.com/chewxy/math32"
</code></pre>
<p>Then you won't need to find and replace</p></pre>ConfuciusBateman: <pre><p>Unfortunately it's all float64 right now, so I'll still need to find and replace right? </p></pre>Redundancy_: <pre><p>"for space reasons" - is there a reason that you think that'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
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传