如何GMP存储其整数,字节上的任意号码? [英] How does GMP stores its integers, on an arbitrary number of bytes?

查看:206
本文介绍了如何GMP存储其整数,字节上的任意号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2 ^ 64仍然是远从无限远我的RAM /硬盘驱动器可以处理...

2^64 is still far from the "infinity" my ram/hard drive can handle...

首先,我想GMP是如何使用的内存/处理器,因为它做一些见不得人的优化的...

First I wonder how GMP works with memory/processor since it does some kind of shady optimisations...

我也想知道是否有关于字节任意数量的存储一个整数(无符号,它更容易)的方式。例如,在50个字节,我将有2 ^ 400 -1的帽。
要做的事情是工作很好地进行,以保持从一个字节到另一个一致的数量,我有一些想法,但我真的不知道这将是这样做的最快方法。我甚至不知道我是否是对的。

I was also wondering if there is a way of storing an integer (unsigned, it's easier) on an arbitrary number of bytes. For example, on 50 bytes, I would have a cap of 2^400 -1. The thing to do is to work well with carries to keep the number consistent from one byte to another, I have some idea about that, but I'm really not sure it would be the fastest way to do this. I'm not even sure if I'm right.

我猜GMP使用这种方式来存储数据,但我只是想一些(甚至略)解释或某些转发一些理论(我没有任何的博士学位,所以不要韧)

I'm guessing GMP uses this kind of way to store its data, but I just want some (even little) explanation or some forwarding to some theory (I don't have any doctorate, so don't be tough).

推荐答案

GMP动态分配空间来重新present数字(并且当它需要成长重新分配)。

GMP dynamically allocates space to represent numbers (and reallocates when it needs to grow).

这是光详细整数内幕描述的,在GMP手动,它描述它是如何口吃了起来重新presentation为四肢,并在一个数组存储四肢。

This is described in light detail in Integer Internals, in the GMP manual, it describes how it chunks up the representation into "limbs" and stores the limbs in an array.

在四肢一词的描述来自 GMP基础知识:命名和类型

The description of the term "limbs" comes from GMP Basics: Nomenclature and Types:

一个肢体意味着,适合在一个字一个多precision数量的一部分。 (我们选择这个词,因为人体的肢体类似于一个数字,仅大,并且包含多个位。)通常肢体包含32个或64位。对肢体的C数据类型是mp_limb_t。

A limb means the part of a multi-precision number that fits in a single word. (We chose this word because a limb of the human body is analogous to a digit, only larger, and containing several digits.) Normally a limb contains 32 or 64 bits. The C data type for a limb is mp_limb_t.

所以,再presenting在GMP的一些作品通过分组一些肢体一起重新present整数的幅度,(符号位双意存储号码存储为符号位四肢)。

So, representing a number in GMP works by grouping a number of limbs together to represent the magnitude of the integer, stored with a sign bit (the sign bit is dual purposed to store the number of limbs).

这是什么意思吗?哦,通常一个Int64是重新在64位psented $ P $。完成。如果您打包一堆这些结合在一起,可以显著增加。把两者结合起来,2 ^ 64 * 2 ^ 64或2 ^ 128。再添加两个四肢,你会得到2 ^ 256。这是一个很大的数字,存储在4个字(加上重新presentation开销)。

What does this mean to you? Well, normally an int64 is represented in 64 bits. Done. If you package a bunch of these together, you can significantly increase that. Put two together, 2^64*2^64, or 2^128. Add two more limbs and you get 2^256. That's a lot of numbers, stored in 4 words (plus the representation overhead).

当然,彩车重新presentation更为复杂(看到这里 ),存储使用尾数(包括符号和大小)和指数再度presentation。

Of course, the representation of floats is more complicated (see here), storing the representation using a mantissa (consisting of a sign and magnitude) and an exponent.

这篇关于如何GMP存储其整数,字节上的任意号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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