Thread: Scale back size of Numbers while maintaining proportion

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    29

    Scale back size of Numbers while maintaining proportion

    Hi,

    I am been given a list of numbers in a certain format [19700, 19900, 79400, 79600, 79800, 179300, 179500, 279799 etc]. There is no maximum value on this list.

    I need to scale back these numbers so that they don't exceed the number 5100 but I need to preserve the proportion of the numbers i.e. 179500 is higher than 79600 which is higher than 79400 etc etc.

    I thought I could do this with mod 5100 but in hindsight that doesn't work...

    Any suggestions would be greatly appreciated about how I should approach this.

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Maybe divide by a common no.?
    ...but that would(for whole no.s) convert some > or < conditions to >= and <= resp.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    29
    Do you mean that some of the numbers could end up the same? I need them to be unique......

    Is there any way to approach this using mod combined with something else?

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    29
    Actually from doing some more searching I think there's no way to do this unless I know the highest number in my list (279799 in the list I gave above). If I know this I can scale it according to the below:

    r = 5100 * (value / Integer_MAX_VALUE)

    e.g. r = 5100 * (79600/279799)

  5. #5
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Actually from doing some more searching I think there's no way to do this unless I know the highest number in my list
    You could find it at runtime....if the lists are not too large to do that nicely.

    Though it doesn't sound like a good idea, I think you could wing it by storing it as a double (if that isn't accurate enough/...use some Arbitrary Precision library....and the associated power of 10 to get back the original number)

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by kerrymaid View Post
    e.g. r = 5100 * (79600/279799)
    Not quite... That would result in zero because you are using integer division there. You would need to do r = 5100 * 79600 / 279799 and let the multiplication happen first. However you will have to be careful to avoid integer overflow. If you get overflow then use a 64-bit data type (fixed or floating).

    Of course none of this prevents the scaling from mapping two input values to the same output value, so according to the below statement, you appear to be screwed:
    Do you mean that some of the numbers could end up the same? I need them to be unique......
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 06-22-2010, 12:31 AM
  2. Replies: 2
    Last Post: 04-24-2010, 11:06 PM
  3. Maintaining 2 SVN Repositories
    By @nthony in forum General Discussions
    Replies: 9
    Last Post: 03-25-2010, 11:58 AM
  4. figuring out size of numbers
    By Chaplin27 in forum C++ Programming
    Replies: 17
    Last Post: 08-05-2005, 12:35 PM
  5. Replies: 3
    Last Post: 07-24-2002, 08:46 AM