XML

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 int

2000

Question 69 (2000):

In a post, Fred says that the maximum negative 32 bit int is -2147483648, so I have coded appropriately ...

  -- ensure seed is positive & legal
  IF
    seed = (-2147483648)       <---------ERROR!!!
      seed := 2147483647
    seed < 0
      seed := -seed
    seed = 0
      seed := 1
    TRUE
      SKIP

But I get an error on the line arrowed above which says:

          Overflow when evaluating constant expresssion

Help!! Have I done something wrong or is the info on cs2 wrong?

Answer 69:

The compiler treats -2147483648 as an expression, so it gets an error when trying to evaluate 2147483648 (which is larger than the largest INT). If it got past that, it would get another error trying to negate it.

occam has a special way of naming the largest and smallest of any of its number types. For example,

  MOSTNEG INT
  MOSTPOS INT

give you, respectively, the most negative and positive integers. Other ways we can write MOSTNEG INT are:

  #80000000
  1 << 31

But ... my colleague, David Wood, suggests you might like to consider:

  TIMER tim:
  INT seed:
  SEQ
    tim ? seed
    seed := (seed >> 2) + 1

Keywords: inverting , int , random , q7

Referrers: Question 29 (2002)

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:27 2013
This document is maintained by Fred Barnes, to whom any comments and corrections should be addressed.