2008/4/27 Robert Dewar <[EMAIL PROTECTED]>: > > > Fortunately there is a assembler instruction to do just this on most CPUs. > > e.g. jo, jc, js > > It would be nice to be able to write this sort of C code. > > > > int a,b,c; > > a = b + c; > > if (a overflowed) { > > handle_overflow(); > > } > > > > Yes, but there is no such feature > > > > > > One cannot simply code a special function to test the carry/overflow > > flags as the compiler might reorder the previous instructions, and > > therefore the carry/overflow state gets messed up. > > > > Right indeed. > You could code an addition function that did an overflow check and > call that function > > > > > > Why has the C language lacked this sort of functionality for so long? > > > > It would be a major language change, there are of course languages (e.g. > Ada) that handle this conveniently and properly. To me, the more > interesting question is how on earth Java missed this fundamental > requirement. > > > > > James > > > >
I think Java handles it OK for floats. I.e. Tests for positive infinity and negative infinity etc. I don't think Java handles it for integer maths. I agree with you. Big oversight for the Java spec developers. It would have been nice to also have some good handling of reals but that is a compete other story.