raphnguyen
raphnguyen

Reputation: 3605

char or float overflow

Unsure how to tell if an overflow is possible. I am given this sample code:

char x;  
float f, g;  
// some values get assigned to x and f here...  
g = f + x;  

Can someone please explain?

Upvotes: 1

Views: 197

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798626

A float, at its highest limits (binary exponent of 127), does not have sufficient precision (23 bits) to show a difference of the largest possible char (127, 7 bits), and so overflow is not possible since addition will have no effect (a precision of 127-7=120 would be required).

Upvotes: 5

Related Questions