C ++或Java中的Biggger Integers! [英] Biggger Integers in C++or java !

查看:67
本文介绍了C ++或Java中的Biggger Integers!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作大数字并将它们用于算术。

数字真的......非常......很大..(多少是极限?)

将两个巨大的数字相乘并使其更大?

我想要一个计划吗?

我不打算使用任何额外的包(GMP,BigInteger,LargeInteger等) ..我已经用谷歌搜索了他们)。

有什么可能做这样的事情!!!

I want to make big numbers and use them for arithmetics.
Numbers really..reallly ..reallly big ..(HOW MUCH IS THE LIMIT?)
Multiply two huge numbers and make it even bigger?
I want a plan to do it?
I dont plan to use any extra packages(GMP,BigInteger,LargeInteger, etc.. i already googled them).
What could possibly be the way to do such a thing!!!

推荐答案

你可以查一下限制:

http://www.cplusplus.com/reference/climits/ [ ^ ]



http://docs.oracle.com/javase/7 /docs/api/java/lang/Integer.html [ ^ ]



两者c ++和java依赖于您使用的底层架构。因此在x32系统上,寄存器大小为32位,通常通过组合2个寄存器(eax和edx)来伪造更大的数字。由于没有硬件支持,因此需要在特殊功能中实现对更大数字的支持。这会让它们变慢。这适用于java和c ++。



使用java的优点是jit编译器将为其运行的实际体系结构编译程序。因此,在x64上运行时,为32位系统编译的c ++程序将不会使用64位寄存器大小。 java程序将使用较大的寄存器,因为java运行时将自动优化它。



祝你好运!
You can check the limits:
http://www.cplusplus.com/reference/climits/[^]

http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html[^]

Both c++ and java depend on the underlying architecture you use. So on an x32 system the register size is 32bits and bigger numbers are often faked by combining 2 registers (eax and edx). Support for even bigger numbers needs to be implemented in special functions because there is no hardware support. This will make them slower. This goes for both java and c++.

Advantage with java is that the jit compiler will compile the program for the actual architecture it runs on. So a c++ program compiled for a 32 bit system will not use 64bit register sizes when running on x64. A java program will use the larger registers because the java runtime will optimize for it automatically.

Good luck!


限制是代码在加载所有代码后可以访问的最大地址空间块。对于一个32位进程,你正在谈论2 ^(2 ^ 40)的 order



实际实现一个大数目:



- 弄清楚你想要如何表示数字(固定点或浮点数)

- 决定你想要多少精度(固定或可变数量的位)



然后编写一个类并支持实现数据表示的自由函数以及所需的所有算术运算。前两个决定着色了该类其余部分的样子,因此在做出这些决定之前,对任何更多的实现问题进行评论有点困难。
The limit is the largest lump of address space your code can access after all the code is loaded. For a 32 bit process you're talking on the order of 2^(2^40).

To actual implement a large number:

- work out how you want to represent the number (fixed point or floating point)
- decide how much precision you want (fixed or variable number of bits)

then code up a class and supporting free functions that implements the data representation and all the arithmetic operations you need. The first two decisions colour what the rest of the class looks like so it's a bit hard to comment on any more implementation issues until you made those decisions.


这篇关于C ++或Java中的Biggger Integers!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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