Recursive Factorial Function Limits
Hi all,
Am trying to work with irrational numbers in Max, specifically the binomial expansions used to approach their 'true' value. For this I needed to be able to work with Factorials, and couldn't find anything on the forums so wrote my own recursive function.
Here it is:
As you can tell, it works fine for all values (apart from 0) up to 12, where the limits of the number boxes start to affect the calculation (print the output of the * . . object to see what it's doing). I'm unfamiliar with many aspects of Max, and as such don't know of any object or attribute for number boxes that can allocate more memory to handle these large numbers.
Can anyone help me out? It's not a matter of life and death as I wouldn't really need numbers that large in my current calculations, but for the future or purely for the sake of completion, it would be good to know my options/alternatives.
Thanks.
You're hitting the limits of 32-bit integers in your multiplication and division objects. The largest integer that can be represented by a signed 32-bit integer is 2,147,483,647. The value of 13! is much greater than that.
If you use floating point in your multiplication and division objects you can have calculations that produce much greater values (you can get to 32! or so with 32-bit floating point, and a good deal higher with 64-bit fp). To get the multiplication and division objects to work in floating point, you need to initialize them with a floating point value (e.g., [* 1.0] or [/ 1.0]). You need to read up about the difference between integers and floating point in Max objects.
Note that floating point has it's own sets of limitations and idiosyncrasies. In particular, 32-bit floats are often only accurate to about six decimal places, so with large numbers you may find that the least significant digits aren't actually what you expect (most people hit this problem with fractions, and this forum is littered with questions from people bitten by that problem). 64-bit floats provide greater accuracy, but it's also not infinite. I always recommend Peter Elsea's tutorials on floating point, although this is covered in many books on programming and machine arithmetic.
Jitter matrix processing is convenient for problems like this since you can declare them as float64. Once you wrap your head around jit.expr and jit.dimop this is a fairly simple approach.
Cheers for the responses guys, I'll have a look at the Jitter objects mentioned, but for now I realised that although I'd set the number boxes as floats, the * and / objects were translating the numbers into integers. It's now working for far larger values.
Here's my edit...
Thanks again for the help!
Thank you very much!
I was going down into this dark tunnel of Max idiosyncrasies that are not so obvious.
Now I see some light... I just had to thank you guys. Now I have a few new approaches to try.