#include <stdio.h> // for printf()
#include <limits.h>
#include <math.h> // for pow()
// computed integral limits, including char
int main()
{
int size = pow(2,sizeof(char)*8-1)-1;
printf("2^(sizeof(char)*8-1)-1:\t\t %d\n", size);
printf("CHAR_MAX:\t\t\t %d\n", CHAR_MAX);
size = -pow(2,sizeof(char)*8-1);
printf("-2^(sizeof(char)*8-1):\t\t%d\n", size);
printf("CHAR_MIN:\t\t\t%d\n", CHAR_MIN);
size = pow(2,sizeof(char)*8)-1;
printf("2^(sizeof(char)*8)-1:\t\t %d\n", size);
printf("UCHAR_MAX:\t\t\t %d\n", UCHAR_MAX);
size = pow(2,sizeof(short)*8-1)-1;
printf("2^(sizeof(short)*8-1)-1:\t %d\n", size);
printf("SHRT_MAX:\t\t\t %d\n", SHRT_MAX);
size = -pow(2,sizeof(short)*8-1);
printf("-2^(sizeof(short)*8-1):\t\t%d\n", size);
printf("SHRT_MIN:\t\t\t%d\n", SHRT_MIN);
size = pow(2,sizeof(short)*8)-1;
printf("2^(sizeof(short)*8)-1:\t\t %d\n", size);
printf("USHRT_MAX:\t\t\t %d\n", USHRT_MAX);
size = pow(2,sizeof(int)*8-1)-1;
printf("2^(sizeof(int)*8-1)-1:\t\t %d\n", size);
printf("INT_MAX:\t\t\t %d\n", INT_MAX);
size = -pow(2,sizeof(int)*8-1);
printf("-2^(sizeof(int)*8-1):\t\t%d\n", size);
printf("INT_MIN:\t\t\t%d\n", INT_MIN);
unsigned usize = pow(2,sizeof(int)*8)-1;
printf("2^(sizeof(int)*8)-1:\t\t %u\n", usize);
printf("UINT_MAX:\t\t\t %u\n", UINT_MAX);
long int lsize = pow(2,sizeof(long)*8-1)-1;
printf("2^(sizeof(long)*8-1)-1:\t\t %ld\n", lsize);
printf("LONG_MAX:\t\t\t %ld\n", LONG_MAX);
lsize = -pow(2,sizeof(long)*8-1);
printf("-2^(sizeof(long)*8-1):\t\t%ld\n", lsize);
printf("LONG_MIN:\t\t\t%ld\n", LONG_MIN);
unsigned long int ulsize = pow(2,sizeof(long)*8)-1;
printf("2^(sizeof(long)*8)-1:\t\t %lu\n", ulsize);
printf("ULONG_MAX:\t\t\t %lu\n", ULONG_MAX);
long long int llsize = pow(2,sizeof(long long)*8-1)-1;
printf("2^(sizeof(long long)*8-1)-1:\t %lld\n", llsize);
printf("LLONG_MAX:\t\t\t %lld\n", LLONG_MAX);
llsize = -pow(2,sizeof(long long)*8-1);
printf("-2^(sizeof(long long)*8-1):\t%lld\n", llsize);
printf("LLONG_MIN:\t\t\t%lld\n", LLONG_MIN);
unsigned long long int ullsize = pow(2,sizeof(long long)*8)-1;
printf("2^(sizeof(long long)*8)-1:\t %llu\n", ullsize);
printf("ULLONG_MAX:\t\t\t %llu\n", ULLONG_MAX);
return 0;
}
/*
gcc computed.c -o computed -lm // link math library
// warnings: conversion from double to long
./computed
2^(sizeof(char)*8-1)-1: 127
CHAR_MAX: 127
-2^(sizeof(char)*8-1): -128
CHAR_MIN: -128
2^(sizeof(char)*8)-1: 255
UCHAR_MAX: 255
2^(sizeof(short)*8-1)-1: 32767
SHRT_MAX: 32767
-2^(sizeof(short)*8-1): -32768
SHRT_MIN: -32768
2^(sizeof(short)*8)-1: 65535
USHRT_MAX: 65535
2^(sizeof(int)*8-1)-1: 2147483647
INT_MAX: 2147483647
-2^(sizeof(int)*8-1): -2147483648
INT_MIN: -2147483648
2^(sizeof(int)*8)-1: 4294967295
UINT_MAX: 4294967295
2^(sizeof(long)*8-1)-1: 9223372036854775807
LONG_MAX: 9223372036854775807
-2^(sizeof(long)*8-1): -9223372036854775808
LONG_MIN: -9223372036854775808
2^(sizeof(long)*8)-1: 18446744073709551615
ULONG_MAX: 18446744073709551615
2^(sizeof(long long)*8-1)-1: 9223372036854775807
LLONG_MAX: 9223372036854775807
-2^(sizeof(long long)*8-1): -9223372036854775808
LLONG_MIN: -9223372036854775808
2^(sizeof(long long)*8)-1: 18446744073709551615
ULLONG_MAX: 18446744073709551615
*/
Comments
Post a Comment