Location: Arithmetic

Discussion: Advanced Increment/Decrement ChipReported This is a featured thread

Showing 4 posts

IEF015
Advanced Increment/Decrement Chip
Apr 17 2008, 4:02 PM EDT | Post edited: Apr 17 2008, 4:02 PM EDT
Name: Advanced Increment/Decrement Gate
Author: IEF015
Edited Chip: Increment/Decrement
Description: Increment/Decrement Gate with reset and more features.
Example Uses:

CODE:

N@Adv. Inc/Dec Chip v1
I@A Inc Dec Reset ResetTo Max Min
O@Value
Value += Inc * A
Value += Dec * -A
Reset -> Value = ResetTo;
Value > Max -> Value = Max;
Value < Min -> Value = Min;
ResetTo ? ResetTo : 0

Code explaination:

Line 1: "Value" equals "A" added when "Inc" is on
Line 2: "Value" equals "A" subtracted when "Dec" is on
Line 3: When "Reset" is on, "Value" equals "ResetTo"
Line 4: When "Value" is greater than "Max", then "Value" equals "Max"
Line 5: When "Value" is less than "Min", then "Value" equals "Min"
Line 6: When ResetTo has no input, then ResetTo will default to 0
0  out of 1 found this valuable. Do you?    

MagnetoHydroDynamics
1. RE: Advanced Increment/Decrement Chip
May 30 2008, 4:33 PM EDT | Post edited: May 30 2008, 4:33 PM EDT
You might wanna add an A input
And do this:
~Inc & Inc == 1 -> Value += A
~Dec & Dec == 1 -> Value -= A

Instead of Line 4 and 5 use this:
Value = clamp(Min, Value, Max)

You can even go as far as:
Value = clamp(Min, (~Inc & Inc == 1 ? Value + A : (~Dec & Dec == 1 ? Value - A : Value)), Max)
And simply fit it all into one line.
Do you find this valuable?    

IEF015
2. RE: Advanced Increment/Decrement Chip
May 31 2008, 5:36 PM EDT | Post edited: May 31 2008, 5:36 PM EDT
This is the one I use now:

N@Adv. Inc/Dec Chip v1
I@AI AD Inc Dec Reset ResetTo Max Min
O@Value
Value += Inc * AI
Value += Dec * -AD
Reset -> Value = ResetTo;
Value > Max -> Value = Max;
Value < Min -> Value = Min;
Do you find this valuable?    

MagnetoHydroDynamics
3. RE: Advanced Increment/Decrement Chip
Jun 1 2008, 4:43 AM EDT | Post edited: Jun 1 2008, 4:43 AM EDT
Ah i see, you have a boolean value as Inc and Dec...
You might wanna use the clamp command instead of line 4 and 5:
N@Adv. Inc/Dec Chip v1
I@A Inc Dec Reset ResetTo Max Min
O@Value
Value += Inc * A
Value += Dec * -A
Value = (Reset ? ResetTo : Value)
Value = clamp(Min, Value, Max)
Do you find this valuable?    

Related Content

  (what's this?Related ContentThanks to keyword tags, links to related pages and threads are added to the bottom of your pages. Up to 15 links are shown, determined by matching tags and by how recently the content was updated; keeping the most current at the top. Share your feedback on Wetpaint Central.)