The Nightstar Zoo

Nightstar IRC Network - irc.nightstar.net
It is currently Mon Dec 18, 2017 9:43 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Operations.
PostPosted: Fri Oct 21, 2005 11:16 am 
Offline
Intern
Intern
User avatar

Joined: Sat Dec 11, 2004 4:13 pm
Posts: 1139
Location: Ground floor, first room on the right.
On today's lecture I've had some doubts about my professor's oppinion.

He said that this thing:
Code:
2x+4
----
ax^2


Was better represented as (2*x+4)/a/x/x than (2*x+4)/(a*x*x). Is that right? And why? I don't get it.

_________________
It's the real me, I swear!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 11:37 am 
Performance reasons. Sometimes you have to sacrifice some readability for the purpose of prematurely deoptimizing.


Top
  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 11:46 am 
Offline
Energizer Bunny
User avatar

Joined: Wed May 22, 2002 12:24 am
Posts: 1634
Yeah I'm not sure where he's getting that.

For the record division is /always/ slower than multiplication, by a factor of about ten.

Vorn


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 12:41 pm 
Offline
Intern
Intern
User avatar

Joined: Sat Dec 11, 2004 4:13 pm
Posts: 1139
Location: Ground floor, first room on the right.
Pi wrote:
Performance reasons. Sometimes you have to sacrifice some readability for the purpose of prematurely deoptimizing.


Uh... what's this 'premature deoptimization' you speak of?

_________________
It's the real me, I swear!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 12:48 pm 
Offline
Energizer Bunny
User avatar

Joined: Wed May 22, 2002 12:24 am
Posts: 1634
Premature optimization means trying to improve the performance characteristics of a system before you know what performance characteristics need improving.

Premature deoptimization is, well. Silly.

Vorn


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 22, 2005 7:51 am 
Offline
Intern
Intern
User avatar

Joined: Sat Dec 11, 2004 4:13 pm
Posts: 1139
Location: Ground floor, first room on the right.
Wait, you mean to say that... I should intentionally degrade the performance of the code? That is silly.

_________________
It's the real me, I swear!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 22, 2005 11:01 am 
AnnoDomini wrote:
Wait, you mean to say that... I should intentionally degrade the performance of the code? That is silly.


Well, if you read that "premature optimization" thread you'll see we all agree readability should be the priority unless other needs are overwhelming. That the prof's code would be slower makes it even worse, but it should be rejected on readability grounds alone.


Top
  
 
 Post subject:
PostPosted: Sat Oct 22, 2005 4:46 pm 
Offline
Intern
Intern
User avatar

Joined: Sat Dec 11, 2004 4:13 pm
Posts: 1139
Location: Ground floor, first room on the right.
Yay! *Grins* I was right! I was right!

_________________
It's the real me, I swear!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 4:10 am 
Offline
Safari Exhibit
Safari Exhibit
User avatar

Joined: Mon Feb 07, 2005 3:48 am
Posts: 151
Location: Durban, South Africa
It's possible that $prof was concerned about an overflow in the denominator when x and/or a are large. Unless you're using inappropriately small datatypes, however, this shouldn't be a concern.

As an aside, does someone who knows floating point better than I do want to comment on the (infinitessimal) accuracy/precision differences between the two?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 12:50 pm 
Floating point tracks a number in the form "#.#########" (in binary, this becomes "1.#######"), as well as the sign and magnitude of the number.

In other words, floating point numbers are: (+/-)X * 2^Y.

Thus, magnitude is rarely important (except for very small or very large numbers). What matters for precision is number of significant digits.

So in short, I'm hard pressed to think of a practical case where the denominator would overflow. This happens in astronomy, when you typically deal in ridiculous orders of magnitude, though.


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group