[Lazarus] Off topic maths question with real constant and trunc() statement.

Peter Williams pewilliams2010 at live.com
Fri Mar 11 07:23:01 CET 2011


Hi All,
I have a slightly off-topic maths question based on the following of my Delphi legacy code.
var   max_x, max_y, max_loop : integer;begin  max_x := 35;  max_y := 90;  max_loop := trunc( max_x * max_y / 1.575 ); // gives 2000 for 35 x 90[...]
Is 1.575 represented as a fraction? It does not seem to be. It (for what it's worth) is the square_root( 2.480625 )... but it does not seem to have any relevance.
What is the significance of the magic number. Max_x and Max_y are the dimensions of a 2D array and max_loop is the target population which I will filling the array with. This code goes back to year 2000 and I have no idea where the number 1.575 comes from... but it seems to work as the comment suggests. E.g. the max_loop assignment in that example gives 2000.
Any ideas as to the meaning of the constant? And can this be simplified? I don't think so.
NB - No correlation between max_loop and year 2000... just a coincidence :-)
Best Regards,PEW 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110311/d4773e8b/attachment-0002.html>


More information about the Lazarus mailing list