posted 4 years ago

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

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

posted 4 years ago

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

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

posted 4 years ago

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)

luck, db
*There are no new questions, but there may be new answers.*

posted 4 years ago

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

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

posted 4 years ago

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?

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?

posted 4 years ago

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

luck, db
*There are no new questions, but there may be new answers.*

posted 4 years ago

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

"Leadership is nature's way of removing morons from the productive flow" - Dogbert

Articles by Winston can be found here

posted 4 years ago

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

Winston

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

Articles by Winston can be found here

posted 4 years ago

Can't help it. Deadline is a deadline. no alternative for that.. :-D

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