当你在java中将浮点数转换为定点数时会发生什么(特别是java me)
我希望我的 java me 程序尽可能高效地运行。我的目标是进行光线投射,并想知道遍历体素的最佳方法。我听说浮点数的转换和比较非常消耗CPU。所以我想为什么不给每条射线 x 和 y 添加一定的距离,截断余数,然后使用这些坐标来检查八叉树中的体素。基本上,是否有更好的方法来为 java me 程序执行类似的操作?
截断浮点数?
I want my java me program to run as efficiently as possible. my goal is to make a ray cast and want to know the best way to traverse voxels. I have heard that conversion and comparison of floating point numbers is very CPU intensive. So I figured why not add a certain distance to each rays x and y, truncate the remainder, and use those coordinates to then check an octree for a voxel. Basically, is there a better way of going about doing something like this for a java me program?
Truncating floating point numbers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“浮点数学很慢”是古老的智慧 - 然而,它也是过时的智慧。在现代桌面CPU上,浮点计算速度很快,而定点计算几乎没有什么好处。重读问题标题后编辑:您描述的方法是完全可行的,除了您需要乘法,不添加到每个数字。但是,您应该首先编写一个小型性能测试程序,检查您打算执行的计算类型是否真正受益于您打算运行程序的硬件上的定点数学。
"Floating point math is slow" is old wisdom - however, it is also outdated wisdom. On modern desktop CPUs, floating point computations are fast, and there is little to gain on fixed-point computations.Edit after having reread the question title: The approach you describe is perfectly viable, except that you need to multiply, not add to, each number. However, you should first write a small performance test program that checks whether the kind of computations you intend to do will actually benefit from fixed-point math on the hardware where you intend to run your program.