Geoffrey.Coram wrote: >Div by zero should be an error, whether integer or real. > > For real you can return NaN (not a number) which will propagate through arithmetic like x, so it can be considered a recoverable error - i.e. the program doesn't need to terminate. From a performance standpoint it's probably cheaper to evaluate a large piece of arithmetic without checking for zeros and just check at the end for NaN. >What happens when I write this: > >integer a, res; >a = 0; >res = 5 + (1/a); > >1/a is now "x" but then is converted/coerced to integer(?) >for addition with 5. What is the result of that "conversion"? > > x - it's a 4-state '+' because it is a 4-state '/'. >How do you make "x" an integer? Do you get an error because >the simulator can't convert it to an integer? That's sort of >indirect. > > I think SV just maps 4-state x/z to 2-state 0 (silently), so if "res" was 2-state it would become 0. This would be simpler if you could do C++ style try/catch around suspect code and have the language throw exceptions for division by zero or bad mappings, but I don't think you'll be seeing that in AMS or SV (ever). Kev. >-Geoffrey > > > >Kevin Cameron wrote: > > >>Not much you can do about integer division by zero. Presumably this will >>have to be addressed in SV which supports 2-state types (where x cannot >>be the result) - I can't remember it coming up. >> >>Kev. >> >> > > >Received on Wed Dec 14 16:38:45 2005
This archive was generated by hypermail 2.1.8 : Wed Dec 14 2005 - 16:39:54 PST