简体   繁体   中英

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. 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:

−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. It's performance is impressive.

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

you can also use "unsigned long long" with format specifier "llu". It works fine for 12 digit number in C.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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