简体   繁体   English

在 C 中进行大型数学运算时的结果错误

[英]error in result while doing large mathematical operations in C

I have used long long result;我使用了 long long 结果; to store the result of 150 to power 53 but still it is giving -8 result in C. I dont know what to use to store such large values in C.将 150 的结果存储到 53 次方,但它仍然在 C 中给出 -8 结果。我不知道用什么来在 C 中存储如此大的值。

An integer representation of 150 to the power 53 would require exactly 384 bits. 150 的 53 次方整数表示正好需要 384 位。 The width of long long -- if it's even supported -- could vary, but 128 bits is common, and I would be surprised to see it longer than 256 bits. long long的宽度——如果它甚至被支持——可能会有所不同,但 128 位是常见的,我会惊讶地看到它长于 256 位。

You can represent the value using some variety of bignum library (in which case you would also need to use that library to manipulate it).您可以使用各种 bignum 库来表示该值(在这种情况下,您还需要使用该库来操作它)。 Alternatively, you could store it as a double .或者,您可以将其存储为double A double can represent numbers of that magnitude, but they have limited precision. double可以表示这种数量级的数字,但它们的精度有限。 For many purposes they are entirely sufficient.对于许多目的,它们是完全足够的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM