简体   繁体   English

如何在C中使用12位数字?

[英]How to use 12 digit number in C?

I am dealing with a math example. 我正在处理一个数学例子。 I need to use 12 digit number for my code. 我需要为我的代码使用12位数字。 So which datatype should i use, to use the number in my functions? 那么我应该使用哪种数据类型来使用我的函数中的数字?

If you have a 64-bit integer type, I'd go with that, since it gives you the (18 full digits) range: 如果你有一个64位整数类型,我会选择它,因为它给你(18个全数字)范围:

−9,223,372,036,854,775,808 to
+9,223,372,036,854,775,807

For other tasks (even bigger integers or massive floating point values), I use GMP , the GNU multi-precision library. 对于其他任务(甚至更大的整数或大量浮点值),我使用GMP ,即GNU多精度库。 It's performance is impressive. 它的表现令人印象深刻。

64位整数( longint64_tunsigned longuint64_t )应该可以解决这个问题,或者如果需要小数,则需要doublelong double

you can also use "unsigned long long" with format specifier "llu". 你也可以使用格式说明符“llu”的“unsigned long long”。 It works fine for 12 digit number in C. 它适用于C中的12位数字。

unsigned long long i=600851475143;
printf("%llu",i);

在寻找名为Bignum的图书馆时,我发现了这个维基页面

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

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