浮点字节序? [英] Floating point Endianness?

查看:31
本文介绍了浮点字节序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为实时离岸模拟器编写客户端和服务器,并且由于我必须通过套接字发送大量数据,因此我使用二进制数据来最大化我可以发送的数据量.我已经知道整数字节序,以及如何使用 htonlntohl 来规避字节序问题,但是我的应用程序,几乎所有的模拟软件,都处理大量的浮点数.

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.

这篇关于浮点字节序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆