Floating point Endianness?(浮点字节序?)
问题描述
我正在为实时离岸模拟器编写客户端和服务器,并且由于我必须通过套接字发送大量数据,因此我使用二进制数据来最大化我可以发送的数据量.我已经知道整数字节序,以及如何使用 htonl
和 ntohl
来规避字节序问题,但是我的应用程序,几乎所有的模拟软件,都处理大量的浮点数.
I'm writing a client and a server for a realtime offshore simulator, and, as I have to send a lot of data through a socket, I'm using binary data to maximize the amount of data I can send. I already know about integers endianness, and how to use htonl
and ntohl
to circumvent endianness issues, but my application, as almost all simulation software, deals with a lot of floats.
我的问题是:在处理浮点数的二进制格式时是否存在字节序问题?我知道我的代码将运行的所有机器都使用浮点的 IEEE 实现,但是在处理浮点数时是否存在一些字节序问题?
My question is: Is there some issue of endianness when dealing with binary formats of floating point numbers? I know that all the machines where my code will run use IEEE implementation of floating points, but is there some endianness issue when dealing with floats?
由于我只能访问具有相同字节序的机器,因此我无法自己测试.所以,如果有人能帮助我,我会很高兴.
Since I only have access to machines with the same endian, I cannot test this by myself. So, I'll be glad if someone can help me with this.
推荐答案
是的,浮点数可以依赖字节序.请参阅将浮点值从大端转换为小端有关信息,请务必阅读评论.
Yes, floating point can be endianess dependent. See Converting float values from big endian to little endian for info, be sure to read the comments.
这篇关于浮点字节序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:浮点字节序?


基础教程推荐
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07