-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathexercise1.c
31 lines (25 loc) · 811 Bytes
/
exercise1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* Exercise 1
Find out what your system does with integer overflow, floating-point overflow,
and floating point underflow by using the experimental approach; that is,
write programs that have these problems.
*/
#include <stdio.h>
#include <limits.h>
#include <float.h>
int main(void)
{
int int_overflow;
int MAX_INTEGER = INT_MAX;
float flt_overflow, flt_underflow;
float MIN_FLOAT = FLT_MIN;
float MAX_FLOAT = FLT_MAX;
// artificially create over/underflow
int_overflow = INT_MAX + 1;
flt_overflow = FLT_MAX * 2.;
flt_underflow = FLT_MIN / 2.;
// print results
printf("Max integer: %d \tMax integer + 1: %d\n", INT_MAX, int_overflow);
printf("Max float: %f \tMax float * 2: %f\n", FLT_MAX, flt_overflow);
printf("Min float: %f \tMin float / 2: %f\n", FLT_MIN, flt_underflow);
return 0;
}