Raised This Month: $51 Target: $400
 12% 

Function with Low/High Constraints...


Post New Thread Reply   
 
Thread Tools Display Modes
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 09-08-2005 , 11:26  
Reply With Quote #11

I don't see that you've changed it to add offsets significantly lower than the low constraint.
Brad is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 09-08-2005 , 11:38  
Reply With Quote #12

Hmm..

If you'd call function(1, 12, 3, -25)
It should do:

Code:
function(low /*1*/, high/*12*/, seed/*3*/, offset/*-25*/) {    new numElements = high - low + 1; // = 12 - 1 + 1 = 12    offset += seed - low; // += 3 -1 => now equals -23        if (offset >= 0)       return low + (offset % numElements);    else // This branch gets chosen       return high - (abs(offset) % numElements) + 1; // return 12 - (23 % 12) + 1 => return 12 - 11 + 1 => return 2    return 0;    // Makes the compiler happy -_- }

So it returns 2, which should be ok.
__________________
hello, i am pm
PM is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 09-08-2005 , 12:07  
Reply With Quote #13

When will you learn not to believe everything I say? I think your code is probably right.

Glad you could make use of the new abs() function. Using it in this context is the original reason I brought up the fact that it was missing.
Brad is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 09-08-2005 , 15:16  
Reply With Quote #14

My idea for the function name was clamp_rollover. I like it.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 09-08-2005 , 23:14  
Reply With Quote #15

Should the new function have an idiot check? For example, a person reversing the low and high parameters.
Brad is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 09-09-2005 , 06:04  
Reply With Quote #16

Quote:
Originally Posted by Brad Jones
Should the new function have an idiot check? For example, a person reversing the low and high parameters.
zomg, I don't think so, you'll be probably the only one using it anyway
__________________
hello, i am pm
PM is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 09-09-2005 , 07:10  
Reply With Quote #17

Oh, lots of people will be using it once I unveil the reason I'm using it. There will be oohs and ahs. Maybe even a parade.

Everyone likes a good parade.
Brad is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 09-16-2005 , 06:47  
Reply With Quote #18

Sorry to beat a dead horse but...

OH! OH! I FOUND IT! I did! I did! I did!

Only... The function that I couldn't remember (the one that sparked this thread) doesn't actually do everything I thought it did.

Quote:
Originally Posted by core.inc
Returns value if it is in the range min-max, min if value is lower than min, max if higher than max.

Syntax:
clamp ( value, min=cellmin, max=cellmax )

Type:
Native
This is what I was originally thinking of. Now I'm wondering if the new functionality, derived from the conversation on this thread, should/could be added to clamp() rather than creating a new function for it. I thinking along the lines of an optional 4th parameter that would accept a boolean or enum value indicating whether the 'value' should be cut off at min/max or if the 'value' should rollover.

The function's new signature could be...
Code:
clamp ( value, min=cellmin, max=cellmax, rollover=false )
Anyway, just throwing this all out there. I don't really care if it's the same or a separate function.
Brad is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 09-16-2005 , 08:46  
Reply With Quote #19

Quote:
Originally Posted by Brad Jones
Sorry to beat a dead horse but...

OH! OH! I FOUND IT! I did! I did! I did!

Only... The function that I couldn't remember (the one that sparked this thread) doesn't actually do everything I thought it did.

Quote:
Originally Posted by core.inc
Returns value if it is in the range min-max, min if value is lower than min, max if higher than max.

Syntax:
clamp ( value, min=cellmin, max=cellmax )

Type:
Native
This is what I was originally thinking of. Now I'm wondering if the new functionality, derived from the conversation on this thread, should/could be added to clamp() rather than creating a new function for it. I thinking along the lines of an optional 4th parameter that would accept a boolean or enum value indicating whether the 'value' should be cut off at min/max or if the 'value' should rollover.

The function's new signature could be...
Code:
clamp ( value, min=cellmin, max=cellmax, rollover=false )
Anyway, just throwing this all out there. I don't really care if it's the same or a separate function.
That's a good idea, it goes right into my TODO list (I sound like Ado^H^Hlfred)
__________________
hello, i am pm
PM is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 09-16-2005 , 10:57  
Reply With Quote #20

Quote:
Originally Posted by PM
(I sound like Ado^H^Hlfred)
To verify this for myself, where might I find more information on this individual?
Brad is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:08.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode