Home » Developing U++ » U++ TheIDE and Library: Releases and ChangeLogs » Quiz: What is wrong with this code?
Re: Quiz: What is wrong with this code? [message #3958 is a reply to message #3953] |
Tue, 11 July 2006 17:25   |
 |
mirek
Messages: 14262 Registered: November 2005
|
Ultimate Member |
|
|
unodgs wrote on Tue, 11 July 2006 03:15 |
luzr wrote on Mon, 10 July 2006 17:16 |
struct Rect_ {
.....
Pt CenterPoint() const { return Pt((left + right) / 2, (top + bottom) / 2); }
.....
};
...should compute the central point of Rect...
(...fixed).
Mirek
|
Interesting.. looks fine to me..
Normaly computation of center point looks like:
top + (bottom - top) / 2
but it evaluates to:
top + bottom / 2 - top / 2 =
top / 2 + bottom /2 =
(top + bottom) / 2
Is that bug related to const modifier??
|
No. The problem is when top and bottom are ints and top + bottom is negative - "evaluates" is no longer true....
Mirek
[Updated on: Tue, 11 July 2006 17:26] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Thu Jun 26 11:27:48 CEST 2025
Total time taken to generate the page: 0.04098 seconds
|