I have decided to test how numerate (mathematically literate) my readership is. These are questions that one might find in a high school test... except I substituted the set of ints or longs for that of integers and the set of doubles for that of reals.
For each statement, answer true or false.
If x, y, z are ints, ...
- If x < 0, then -x > 0.
- If x = -x, then x = 0.
- If x -y > 0, then x > y.
- If x and y are positive , then x + y > x.
- If x and y are positive, then (double)x * (double)y = (long)x * (long)y.
- If x-y>0 and y-z>0, then x-z>0.
If x, y, z are doubles, ...
- x = x.
- If x>y is false, then x<=y is true.
- If x > 0, then x - x = 0.
- If x and y are positive integers, then x + y > x.
- If x and y are positive integers, then the statement "x + y = x for all y" is false for all x.
- If x <= 0 is false, then x > 0.
- If x and y are longs, then (double)(x + y) = (long)(x + y).
- if x.Equals(y), then x = y.
- If x.Equals(-x), then x = 0.
- if x.ComparesTo(y) < 0, then x < y.
Subtitled: Know Your Edge Cases
:)
Posted by: Brad Wilson | January 09, 2005 at 02:48 PM
Nice test, let's see...
int 1 and 2 are true.
int 3 and 6 should be true, unless there's some nasty trick that I don't grasp right now.
int 4 is false because of possible overflow.
int 5 is false because of possible overflow or rounding errors.
I'm not even going to touch the double section until you tell us that there can be no NaN or Inf values. :)
PS: SharpReader doesn't display any comments for your blog. No idea why that might be so.
Posted by: Chris Nahr | January 10, 2005 at 05:10 AM
Only the two 5s are true, all the others are false.
Posted by: Jeroen Frijters | January 10, 2005 at 07:48 AM
Uhhmm.. The int 5 is also false. I still think the double 5 is true though.
Posted by: Jeroen Frijters | January 10, 2005 at 07:53 AM
int 5 is false as well. (Think: Digits)
Posted by: James Curran | January 10, 2005 at 08:03 AM
If x>y, x-y >0, andd if x
Posted by: aminah | April 23, 2005 at 05:26 AM