Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ TheIDE and Library: Releases and ChangeLogs » Quiz: What is wrong with this code?
Quiz: What is wrong with this code? [message #3951] Mon, 10 July 2006 23:16 Go to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
struct Rect_ {
.....
	Pt     CenterPoint() const              { return Pt((left + right) / 2, (top + bottom) / 2); }
.....
};


...should compute the central point of Rect...

(...fixed).

Mirek
Re: Quiz: What is wrong with this code? [message #3953 is a reply to message #3951] Tue, 11 July 2006 09:15 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

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??
Re: Quiz: What is wrong with this code? [message #3958 is a reply to message #3953] Tue, 11 July 2006 17:25 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
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

Re: Quiz: What is wrong with this code? [message #3971 is a reply to message #3958] Tue, 11 July 2006 23:36 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

luzr wrote on Tue, 11 July 2006 11:25


No. The problem is when top and bottom are ints and top + bottom is negative - "evaluates" is no longer true....



Yes, negatives... they didn't come into my mind Smile
Re: Quiz: What is wrong with this code? [message #10479 is a reply to message #3971] Wed, 11 July 2007 14:12 Go to previous messageGo to next message
pap2k is currently offline  pap2k
Messages: 8
Registered: June 2007
Promising Member
Is it fix ?

the folowing sample produce wrong result on my fresh version :
Pointf center =
Rectf( Pointf(-1.0,82), Pointf(7,-92)).CenterPoint();
Re: Quiz: What is wrong with this code? [message #10480 is a reply to message #10479] Wed, 11 July 2007 14:22 Go to previous message
pap2k is currently offline  pap2k
Messages: 8
Registered: June 2007
Promising Member
I'm stupid man ...
result produce is good ... that's my in mind calculation wich was false.

I'm sory to disturb you.
Previous Topic: Some macro enhancements for TheIde
Next Topic: Fixed QuickTabs DnD refreshing problems. Mouse wheel works in tiny bar too now..,
Goto Forum:
  


Current Time: Tue Apr 30 21:33:21 CEST 2024

Total time taken to generate the page: 0.03272 seconds