Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 小数点后数字转换二进制编码的问题 #5

Open
protectione055 opened this issue Jul 15, 2023 · 0 comments
Open

[BUG] 小数点后数字转换二进制编码的问题 #5

protectione055 opened this issue Jul 15, 2023 · 0 comments

Comments

@protectione055
Copy link

用乘二取整法计算小数点后的二进制码时,达到指定精度后应该截断小数部分取整数。LonLatSegment这个类的构造方法中用Math.Round来实现。

但我发现C#的Math.Round方法做的是四舍五入而不是截断小数,导致了一些预期外的结果。

            var dotSeconds = (seconds - S) * 2048;
            S11 = (uint)Math.Round(dotSeconds);

参考了这个Java实现(repo)直接将double强制转换为int,效果和Trucate是一样的。

我觉得这部分的代码可能需要修改为:

            var dotSeconds = (seconds - S) * 2048;
            S11 = (uint)Math.Truncate(dotSeconds);

附Math.Round的方法描述:

Rounds a double-precision floating-point value to the nearest integral value.

返回结果:
The integer nearest a. If the fractional component of a is halfway between two integers, one of which is even and the >other odd, then the even number is returned. Note that this method returns a System.Double instead of an integral type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant