简体   繁体   English

在Java中将浮点数转换为定点数时会发生什么情况(专门针对Java Me)

[英]What happends when you convert floating point numbers to fixed point numbers in java (java me specifically)

I want my java me program to run as efficiently as possible. 我希望我的java me程序尽可能高效地运行。 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. 我听说浮点数的转换和比较非常占用CPU。 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. 因此,我想出了为什么不对每条射线x和y添加一定距离,截断其余部分,然后使用这些坐标检查八叉树的体素。 Basically, is there a better way of going about doing something like this for a java me program? 基本上,是否有更好的方法可以针对Java Me程序执行类似的操作?

Truncating floating point numbers? 截断浮点数?

"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. 在现代台式机CPU上,浮点计算速度很快,而定点计算几乎没有收益。

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. 但是,您应该首先编写一个小型性能测试程序,以检查您打算执行的计算类型是否真正受益于要在其上运行程序的硬件上的定点数学运算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM