boost :: multiprecision :: uint128_t sizeof为24 [英] boost::multiprecision::uint128_t sizeof is 24

查看:107
本文介绍了boost :: multiprecision :: uint128_t sizeof为24的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基础数学(128/8 = 16)讲不同的话.我有点失望,想要一些答案-因为根据我的习惯,这种表示法(type_num_of_bytes_t)不仅描述了可以放入变量的数据量,而且还描​​述了跨平台固定可变大小,后者对恕我直言更为重要.我在做什么错了?

Basic math (128 / 8 = 16) speaks differently. I'm kinda disappointed and want some answers - since from what I've been used to, that notation(type_num_of_bytes_t) describes not just the amount of data you can put into the variable, but also cross-platform fixed variable size, and the latter is IMHO even more important. What am I doing wrong?

#include "boost/multiprecision/cpp_int.hpp"
using boost::multiprecision::uint128_t;

...

qDebug() << sizeof(uint128_t);

输出:24.

我正在使用标准的x86/64架构CPU,并在Windows上通过vs2013进行编译.

I'm using standard x86/64 architecture CPU, compiling with vs2013 on Windows.

更新:boost版本为1.61.

UPDATE: boost version is 1.61.

推荐答案

以固定的精度使用时,此类型的大小总是比您期望的N位整数大一个机器字:额外的词既存储符号,又存储多少机器整数中的单词实际上是在使用.后者是对较大的固定精度整数的优化,因此1024位整数与128位整数几乎具有相同的性能特征,而不是加法慢4倍,乘法慢16倍(假定所涉及的值)总是适合128位).通常,这意味着您可以为最坏的情况"使用足够宽的整数类型,即使性能在大多数情况下实际上可以使用较窄的类型来完成,也只会造成轻微的性能下降.

When used at fixed precision, the size of this type is always one machine word larger than you would expect for an N-bit integer: the extra word stores both the sign, and how many machine words in the integer are actually in use. The latter is an optimisation for larger fixed precision integers, so that a 1024-bit integer has almost the same performance characteristics as a 128-bit integer, rather than being 4 times slower for addition and 16 times slower for multiplication (assuming the values involved would always fit in 128 bits). Typically this means you can use an integer type wide enough for the "worst case scenario" with only minor performance degradation even if most of the time the arithmetic could in fact be done with a narrower type.

额外的机器字(在x86/64 8字节上)使大小为24,而不是预期的16.

The extra machine word (on x86/64 8 bytes) makes the size 24 instead of the expected 16.

这篇关于boost :: multiprecision :: uint128_t sizeof为24的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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