Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: fast normalization

Author: Robert Hyatt

Date: 07:47:32 10/31/03

Go up one level in this thread


On October 31, 2003 at 10:28:53, Charles Roberson wrote:

>On October 31, 2003 at 10:06:53, Ricardo Gibert wrote:
>
>>On October 31, 2003 at 09:04:41, Charles Roberson wrote:
>>
>>>
>>>   I have a list of numbers that I wanted to normalize to the range of 0-100.
>>>   The numbers are integers so the obvious thought is
>>>      find largest
>>>      foreach number
>>>         number = number*100/largest
>>
>>Since the "/largest" does not change within the loop, it can be moved outside
>>the loop. In this way, only 1 division is performed for all the numbers of the
>>set. Acceptable if the set is large. Making this idea work requires some
>>elaboration, but is quite workable.
>>
>
>     Algebra allows factoring out the 100/largest and creating a loop invariant
>  constant. However, largest can be very big and we are using integer
>  arithmetic. Thus, a large largest can make 100/largest = 0.


make 100/largest a float.  let number stay an integer.  You end up with
an integer result that will be what you expect.



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.