MIN...MAX and neg. Number
Archiver
Posts: 46,084
Hi
I like to limit the Variable "DegOut" to a min = 1 and max = 410
but my DegOut can be positive and negative.
All numbers smaller 1 should be =1 including the negative numbers
I used this:
DegOut = DegOut MAX 410 MIN 1
but wrong, when DegOut gets negative it gets 410 (65535,limitet to 410)
but I would like to resave a "1"
I tried:
DegOut = ABS DegOut MAX 410 MIN 1
but this just convert the neg. Number to positive numbers
how could I do it ?
Thanks for any help
Heinz Schwenk Germany
I like to limit the Variable "DegOut" to a min = 1 and max = 410
but my DegOut can be positive and negative.
All numbers smaller 1 should be =1 including the negative numbers
I used this:
DegOut = DegOut MAX 410 MIN 1
but wrong, when DegOut gets negative it gets 410 (65535,limitet to 410)
but I would like to resave a "1"
I tried:
DegOut = ABS DegOut MAX 410 MIN 1
but this just convert the neg. Number to positive numbers
how could I do it ?
Thanks for any help
Heinz Schwenk Germany
Comments
better:
DegOut = 1 - DegOut.BIT15 * ( DegOut MAX 410 ) + DegOut.BIT15 MIN 1
This solution takes advantage of the fact that a negative value will
have the high order bit set. Works for -32768 <= DegOut < 32768.
Regards,
Steve
On 6 Mar 03 at 22:16, HSchwenk_GMX wrote:
> Hi
> I like to limit the Variable "DegOut" to a min = 1 and max = 410 but
> my DegOut can be positive and negative. All numbers smaller 1 should
> be =1 including the negative numbers...
I think Steve's solution is very clever! Since there is often more
than one way to do things, here is mine, not necessarily better...
If first offsets your value so that is will be positive, then does
the min and max, and then restores the offset.
degout = degout + 32767 min 32768 max 33177 - 32767
-- Tracy
>This ought to keep you going until somebody comes up with something
>better:
>
>DegOut = 1 - DegOut.BIT15 * ( DegOut MAX 410 ) + DegOut.BIT15 MIN 1
>
>This solution takes advantage of the fact that a negative value will
>have the high order bit set. Works for -32768 <= DegOut < 32768.
>
>Regards,
>
>Steve
>
>On 6 Mar 03 at 22:16, HSchwenk_GMX wrote:
>
>> Hi
>> I like to limit the Variable "DegOut" to a min = 1 and max = 410 but
>> my DegOut can be positive and negative. All numbers smaller 1 should
> > be =1 including the negative numbers...
>
If I read Your solution it looks so easy now
Heinz
Original Message
From: "Tracy Allen" <tracy@e...>
To: <basicstamps@yahoogroups.com>
Sent: Friday, March 07, 2003 2:52 AM
Subject: Re: [noparse][[/noparse]basicstamps] MIN...MAX and neg. Number
> Hi Heinz,
>
> I think Steve's solution is very clever! Since there is often more
> than one way to do things, here is mine, not necessarily better...
> If first offsets your value so that is will be positive, then does
> the min and max, and then restores the offset.
>
> degout = degout + 32767 min 32768 max 33177 - 32767
>
> -- Tracy
>
>
> >This ought to keep you going until somebody comes up with something
> >better:
> >
> >DegOut = 1 - DegOut.BIT15 * ( DegOut MAX 410 ) + DegOut.BIT15 MIN 1
> >
> >This solution takes advantage of the fact that a negative value will
> >have the high order bit set. Works for -32768 <= DegOut < 32768.
> >
> >Regards,
> >
> >Steve
> >
> >On 6 Mar 03 at 22:16, HSchwenk_GMX wrote:
> >
> >> Hi
> >> I like to limit the Variable "DegOut" to a min = 1 and max = 410 but
> >> my DegOut can be positive and negative. All numbers smaller 1 should
> > > be =1 including the negative numbers...
> >
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>