# VOPS problems: For Loop

## Recommended Posts

I am preparing to work on some research for credit at school in the fall, and I want to create all of the pieces parts that I am going to need. The first building block I want to make is a VOPS node for calculating a factorial. Generally speaking I can do this pretty easily in code with this (if i am not mistaken):

var factorial=1
for(i=1,x,i++){
factorial * i = factorial
}

The VOPs network should be about as simple, but I cannot for the life of me figure out how to get the i value for each loop. The help file says this:

Tip

You can use the _i value on the subinput to access the loop iteration variable.

but that means little to nothing to me. Can anyone give me a quick idea of how to do this. I am going to need to use many for loops for the projects I am moving towards, so it would be really nice to be able to access the loop counter.

##### Share on other sites

See attached. 'i' starts at your value and has a step size of -1 and continues while i > 0. Inside you just take '_i' (really 'i') and multiply it by the previous value (starting at 1).

factorial.hip

##### Share on other sites

See attached. 'i' starts at your value and has a step size of -1 and continues while i > 0. Inside you just take '_i' (really 'i') and multiply it by the previous value (starting at 1).

That is an amazing start, took me a second to realize how all of it was working.

Is there any way I can do this without using the point numbers? I am still working on how I will be calculating the stuff, but more ways of doing it would be great. I was trying to make this whole thing into it's own node, which will make it much easier when I go to make the choose function and eventually a binomial, beta and gamma distribution stuff. I am not quite sure where the research stuff will take me, I am just trying to get things I may need put together now. Ideally, I think I will need it to function on it's own, independent of an input, with the option of using one if need be.

I was hoping I could just use the loop to create the factorial and leave the _end value as my "input", basically making it (_end)!

(edit)Don't worry too much about it, I did some fiddling and realized how yours truly worked and got mine to work right too. I had to realize how the output was working to get it right. Sometimes you have to be very sneaky on getting some of these variables to move around right. Thank you so much for your help... now to try to turn the whole thing into it's own node.

##### Share on other sites

Alright... got the factorial working, and a Choose function, but I am running into an interesting error. I am pretty sure I know what is doing it and I don't even know if it is something that can be fixed, but here's hoping.

As n! gets larger, around 13!, there is a massive breakdown in the calculation. The only thing I can think of is that 14! jumps up to a 33-bit number... which means that for some reason this is not being calculated in 64-bit. I am feeling a little slighted, unless there is a way I can mark my factorial node to be calculated as a 64-bit output.

My only option would be to break each number up into smaller sections and work them out that way, but that would get very annoying, and probably more processor intensive. Does anyone have any ideas?

##### Share on other sites

VEX still only processes single precision floats in H12.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×