kent logo

CO538 Anonymous Questions and Answers Keyword Index

This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.

To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.

Keyword reference for overflow


Question 24 (2003):

How is it possible that If I run the process (without inputting anything) at a certain point I start getting negative numbers for the 2nd and 3rd column ?

Answer 24:

This is quite possibly normal behaviour. In standard 32-bit 2's complement signed arithmetic:

    1500000000 PLUS 1500000000 = -1294967296

In occam, you must use the `PLUS' operator to get this behaviour. The standard `+' operator will cause a run-time error when this happens, which is generally what you want.

You might want to consider slowing the output down with a suitable delay. See Question 13 (2000) for how to do this. In relation to Q4, the initial values output by the program should be correct, until something overflows that is. If the output goes negative very early on, then something is probably wrong -- check the values!

Keywords: overflow , negative-numbers

Referrers: Question 26 (2003)

Question 9 (2003):

In `demo.occ', why does the Fibonacci list produce negatives ? Is it to do with the maximum size a number can be ?

Answer 9:

The numbers in the Fibonacci sequence increase very rapidly, and soon exceed the capacity of a 32-bit INT, so integer overflow occurs. The results are then effectively meaningless, and are as likely to be negative as positive.

Unlike programming languages such as Java, occam normally checks for such errors - prefering to crash rather than give wrong answers. However, the component processes in demo.occ use explicitly unchecked arithmetic operators (PLUS, MINUS, TIMES), and not the usual checked ones (+, -, *). If they did not, the run of demo would be rather short!

Keywords: demo.occ , overflow


Question 41 (2000):

Should we be using PLUS/MINUS or +/- for Q4?

My class supervisor told me that we should be using +/-. But when I do that, my q4 process crashes very quickly due to not being able to wrap round into negative numbers. Is this OK or should I use PLUS/MINUS and allow the program to wrap round?

Answer 41:

Please use PLUS/MINUS rather than +/-. That's what the plus process (from the course library) uses and that was chosen specifically to allow these demo programs to run forever. The Fibonacci sequence gets big very quickly - so the demo example program would crash very quickly otherwise. Of course, the numbers in the supposed-Fibonacci column are no longer from the Fibonacci sequence ... but never mind.

However, whether you use PLUS/MINUS or +/-, you will not lose marks. I've squared things with your supervisor!

Keywords: q4 , overflow

Valid CSS!

Valid XHTML 1.0!

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
Last modified Mon May 20 13:50:28 2013
This document is maintained by Fred Barnes, to whom any comments and corrections should be addressed.