确保C ++双精度是64位 [英] Ensuring C++ doubles are 64 bits

查看:117
本文介绍了确保C ++双精度是64位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的C ++程序中,我需要从外部字节序列中提取一个64位的浮点数。有没有一些方法来确保,在编译时,双精度是64位?是否还有其他类型,我应该用来存储数据?

In my C++ program, I need to pull a 64 bit float from an external byte sequence. Is there some way to ensure, at compile-time, that doubles are 64 bits? Is there some other type I should use to store the data instead?

编辑:如果你正在阅读这个和实际上寻找一种方式

If you're reading this and actually looking for a way to ensure storage in the IEEE 754 format, have a look at Adam Rosenfield's answer below.

推荐答案

对于其他答案的改进假设一个字符是8位,标准不保证这一点。)。将是这样:

An improvement on the other answers (which assume a char is 8-bits, the standard does not guarantee this..). Would be like this:

char a[sizeof(double) * CHAR_BIT == 64];

BOOST_STATIC_ASSERT(sizeof(double) * CHAR_BIT == 64);

您可以在< limits.h> < climits>

这篇关于确保C ++双精度是64位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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