Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Bear Bibeault
• Ron McLeod
• Jeanne Boyarsky
• Paul Clapham
Sheriffs:
• Tim Cooke
• Liutauras Vilda
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Tim Holloway
• fred rosenberger
• salvin francis
Bartenders:
• Piet Souris
• Frits Walraven
• Carey Brown

Finding number range with scaling values

Ranch Hand
Posts: 590
6
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

Bartender
Posts: 11445
19
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: 590
6

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 ..

Bartender
Posts: 5167
11
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: 590
6

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: 590
6

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
To offer any meaningful help, we need to see what you've tried, in the form of an SSCCE <- link

Bartender
Posts: 10777
71

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: 590
6
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: 10777
71

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: 590
6

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

 That new kid is a freak. Show him this tiny ad: Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton