Created
November 24, 2017 17:26
-
-
Save classmember/e651b1da92b514ed280aa550da38e344 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Large numbers example using built-in data types | |
* | |
* Author: | |
* Kolby H. <[email protected]> | |
* | |
* Published: | |
* November 24, 2017 | |
* | |
* Usage: | |
* For numbers up to about a quintillion | |
* (1,000,000,000,000,000,000) or (1.0 x10^18). | |
* Limits: | |
* The limitation is based on using a maximum of 64 bits. | |
* | |
* Reference: | |
* ISO/IEC 9899:TC3 | |
* <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf> | |
* | |
* See also: | |
* "C data types" on Wikipedia | |
* <https://en.wikipedia.org/wiki/C_data_types> | |
* | |
* compiled using: | |
* gcc -o example large_number_example.c | |
* | |
* output should look like the following: | |
* # ./example | |
* long long int min: -9223372036854775808 | |
* long long int max: 9223372036854775807 | |
* unsigned long long int min: 0 | |
* unsigned long long int max: 18446744073709551615 | |
*/ | |
#include <stdio.h> | |
#include <stdint.h> | |
#include <inttypes.h> | |
#include <limits.h> | |
int main(int argc, char* argv[]) { | |
/** | |
* Signed long long int | |
* values can range from −9,223,372,036,854,775,807 | |
* to +9,223,372,036,854,775,807 | |
*/ | |
long long int lli_num; | |
lli_num = INTMAX_MIN; // −9,223,372,036,854,775,807 | |
printf("long long int min: %lld\n", lli_num); | |
lli_num = INTMAX_MAX; // 9,223,372,036,854,775,807 | |
printf("long long int max: %lld\n", lli_num); | |
/** | |
* Unsigned long long int | |
* values can range from 0 | |
* to +18,446,744,073,709,551,615 | |
*/ | |
unsigned long long int llu_num; | |
llu_num = 0; | |
printf("unsigned long long int min: %llu\n", llu_num); | |
llu_num = UINTMAX_MAX; // 18,446,744,073,709,551,615 | |
printf("unsigned long long int max: %llu\n", llu_num); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment