• Post Reply Bookmark Topic Watch Topic
  • New Topic

Finding number range with scaling values  RSS feed

 
s ravi chandran
Ranch Hand
Posts: 579
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have an issue with number calculation. This is purely logical issue. I have a NumberRange object with a min and max value, which can be +ve or -ve. Now my issue starts when we put a scaling constraint on this. With normal scaling, it would have been okay. but we have provided option that the scaling can be +ve or -ve.

here is my confusion, suppose i have a scaling from -15.0E to 5.0E. And my numberrange min is -10.0E and max is -6.0E . How to scale it down so that the sign of the range is preserved while still keeping the range value precise. I am still trying a logic... , this looks simple.. just not coming in my mind right now.

Thanks
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the relation between the scale and the range? I am trying to understand what you mean by scaling in this context.
If you are trying to ensure the bounds, you can use something like Math.min and Math.max
 
s ravi chandran
Ranch Hand
Posts: 579
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:What is the relation between the scale and the range? I am trying to understand what you mean by scaling in this context.
If you are trying to ensure the bounds, you can use something like Math.min and Math.max

Thanks for replying. yes scale represents bound entered by user. so whatever be the number range in the process, when a user enters scaling values, I have to ensure that the number range reflects this.

now in my current scenario we are internally converting all the +ve number range values in to -ve . for this case, when a user enters the scale boundary ( in +ve), I can find the absolute difference between them, but how to get the real difference in such a way that the resultant value is subset of the existing number range and not a superset.. then there is the case where the scale value itself is in -ve.

I tried some logics, but my range is almost doubling up.. that means my logic is wrong... i am not able to think of any good solution which will handle this issue in generic way. i want to avoid many if and else conditions to handle combination of +ve/ -ve number range and +ve/ -ve scale values ..

 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Form the problem description, it looks like you need to
  • Translate each value by subtracting (minimum value) - (minimum of scale)
  • Scale the result by multiplying by (maximum of scale - minimum of scale) / (maximum value - minimum value)
  •  
    s ravi chandran
    Ranch Hand
    Posts: 579
    6
    Java jQuery
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Darryl Burke wrote:Form the problem description, it looks like you need to
  • Translate each value by subtracting (minimum value) - (minimum of scale)
  • Scale the result by multiplying by (maximum of scale - minimum of scale) / (maximum value - minimum value)


  • So, do i need to apply both these steps? also, what i tried just now was to use hardcoded values to test the working. so, I have a number range which is in -ve and I have scale values which is in +ve. So, I take the +ve scale max, do a negation and set it as new number range min. then i take +ve scale min, do a negation and set it as new number range max. this works.. but this is specific and also for one particular scenario.

    i can try the above scenario..
     
    s ravi chandran
    Ranch Hand
    Posts: 579
    6
    Java jQuery
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    s ravi chandran wrote:
    Darryl Burke wrote:Form the problem description, it looks like you need to
  • Translate each value by subtracting (minimum value) - (minimum of scale)
  • Scale the result by multiplying by (maximum of scale - minimum of scale) / (maximum value - minimum value)


  • So, do i need to apply both these steps? also, what i tried just now was to use hardcoded values to test the working. so, I have a number range which is in -ve and I have scale values which is in +ve. So, I take the +ve scale max, do a negation and set it as new number range min. then i take +ve scale min, do a negation and set it as new number range max. this works.. but this is specific and also for one particular scenario.

    i can try the above scenario..

    I tried the above logic, but it is failing in the first scenario itself. if my value is in negative. do i need to have an if else condition to calculate the bounds differently if value is in negative? also, if scaling is in negative, does it still apply?
     
    Darryl Burke
    Bartender
    Posts: 5167
    11
    Java Netbeans IDE Opera
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    To offer any meaningful help, we need to see what you've tried, in the form of an SSCCE <- link
     
    Winston Gutkowski
    Bartender
    Posts: 10575
    66
    Eclipse IDE Hibernate Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    s ravi chandran wrote:I tried the above logic, but it is failing in the first scenario itself. if my value is in negative. do i need to have an if else condition to calculate the bounds differently if value is in negative? also, if scaling is in negative, does it still apply?

    What about creating a Bounds class? Then you can supply it with min and max values and apply "scaling" (and I'm still not sure what you mean by that) any way you like.

    Tip: Whenever you're stuck with things like this, try and think of a class that might help you out.

    Winston
     
    s ravi chandran
    Ranch Hand
    Posts: 579
    6
    Java jQuery
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for reply guys. I have done some stop gap arrangement for now. did not get time to come up with a good generic logic. the fix shd work for now. I hope it doesnt break in testing. will get some proper time next time, in case the issue reoccurs.

     
    Winston Gutkowski
    Bartender
    Posts: 10575
    66
    Eclipse IDE Hibernate Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    s ravi chandran wrote:I have done some stop gap arrangement for now. did not get time to come up with a good generic logic. the fix shd work for now...will get some proper time next time

    The epitaph for many a failed system, I fear. Have a look at my signature comment.

    Winston
     
    s ravi chandran
    Ranch Hand
    Posts: 579
    6
    Java jQuery
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Winston Gutkowski wrote:
    s ravi chandran wrote:I have done some stop gap arrangement for now. did not get time to come up with a good generic logic. the fix shd work for now...will get some proper time next time

    The epitaph for many a failed system, I fear. Have a look at my signature comment.

    Winston

    Can't help it. Deadline is a deadline. no alternative for that.. :-D
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!