如何在 Windows 注册表中存储双精度(64 位浮点)或浮点数?
我想将 double
(64 位浮点)存储到 Window 注册表中。最好的方法是什么?
可能的选项:64 位编译器中的 long
和 double
都是 64 位值,因此一种选择是将 double 转换为其 64 位表示形式并存储它作为注册表“qword”。另一种选择是将其存储为二进制流。
I want to store a double
(64-bit floating point) into the Window registry. What's the best way to go about it?
Possible options: both a long
and a double
in a 64-bit compiler are 64-bit values so one option is to convert the double to it's 64-bit representation and store it as a registry "qword". Another option is to store it as a binary stream.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
或者您可以将其存储为 base64 编码的字符串或其他形式。 :)
就我个人而言,我会将其存储为 reg_binary,而不是来回转换,但哪个最简单实际上取决于语言。至于哪一个“更正确”,我会说 reg_binary。但注册表是一个肮脏的黑客行为,如果更容易的话,我不会因为以“错误”的方式做一些事情而感到难过。
Or you could store it as a base64 encoded string, or whatever. :)
Personally though, I'd store it as a reg_binary rather than converting to and fro, but which ever is easiest really depends on the language. As far as which one is "more right" I'd say reg_binary. But the registry is such a dirty hack that I wouldn't feel bad doing something the "wrong" way if it's easier.
您也可以使用字符串。
例如
You could use a string too.
e.g.
我在某处看到的一个聪明的技巧是他们将分子和分母存储为单独的 DWORD,然后在需要时将它们组合起来。
one clever trick I saw somewhere was they would store the numerator and denominoator as separate DWORD's, then combine them when needed.
您可以在此页面。 您应该看一下:
第二个可能看起来最好,但是在这种情况下我使用第三个选项。
flout
和double
类型基于IEEE754
类型,因此您可以轻松地将数字分解为 64 位,并且不会丢失任何精度(与代码>REG_SZ)。
You can find all
Windows registry types
in this page. You should take a look at:The second probably looks best, however, in such cases I use third option.
flout
anddouble
types are basedIEEE754
type, so you can easy explode your number into 64 bits and do not lose any precision (compared withREG_SZ
).