Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Let's bring some liveliness back to the cog forum
Let's bring some liveliness back to the cog forum
2005-04-30, 11:09 AM #1
if I were to write a cog that would contain functions for square root, logarithm (any base), trig and inverse trig, etc... would anyone use these?
I'll probably write them anyway as a learning experience (taylor polynomials btw), but I was just wondering if this would be useful to anyone. You could call them via SendMessageEx() and a value would be returned via ReturnEx().

Here's some examples to give you an idea of how this might work...

squareroot = SendMessageEx(mathcog, user7, n, 0, 0, 0)
...where n is the parameter of the function
result = SendMessageEx(mathcog, user7, n, f, 0, 1)
...where n = the parameter of the function and f determines which (inverse) trig function to use (ie if f = 1, cosine; if f = 3, inverse sine; etc)
logarithm = SendMessageEx(mathcog, user7, n, base, 0, 2);
...where n is the parameter of the function and base is which number will be the base (ie. 10, e,...). I suppose entering 0 will default the base to e

btw, I'm aware there's already a square root one floating around somewhere, but as I said, this will be a learning experience for me (besides, I already started on this one). Also, I'm not sure how useful the log functions may become, but ironically it'll be one of the easier of the functions to write ;)

Lastly, if you have any ideas and such, please share them here. Thanks.
May the mass times acceleration be with you.
2005-05-02, 3:02 AM #2
This place seems dead you might wanna post over at jkhub.
2005-05-02, 3:47 AM #3
I don't think many people would use trig functions, but it would still be worth making them for the 1 - 2 coggers that come into a situation where trig is needed, and that are not able to write the functions themselves.
I remember a time when I worked on a targeting system, when trig functions were the thing I needed most. The lacking of these made the project fail.
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2005-05-02, 9:16 AM #4
Huh?
2005-05-02, 6:54 PM #5
Go for it Darth Slaw. Maybe you will get them done before I do. ;)

:)
2005-05-03, 11:25 PM #6
I know you are doing it yourself and all, but this is what I used for square root...

// square root (d is input value, d1 is output)
d1 = .75 * d;
d1 = .5 * (d1 + d / d1);
d1 = .5 * (d1 + d / d1);
d1 = .5 * (d1 + d / d1);
d1 = .5 * (d1 + d / d1);
d1 = .5 * (d1 + d / d1);
d1 = .5 * (d1 + d / d1);
d1 = .5 * (d1 + d / d1);
d1 = .5 * (d1 + d / d1);
d1 = .5 * (d1 + d / d1);
d1 = .5 * (d1 + d / d1);

The first line is the initial guess, you should adjust this for whether you expect to take square roots of numbers less than or greater than 1. Accuracy is determined by the number of iterations. This uses the newton-raphson approximation.

Not sure of the use of log for odd bases...not too many for 2, e, and 10 to start with.

As for trig functions, I personally have had a need for them several times. I would say they are the most important missing functions even...But I am not sure if the taylor series will work too good for them. I don't remember for sure, but I think it doesn't converge well for some numbers. Maybe you should look into an alternate method, perhaps one that uses lookup tables.

There's also the power function, if you are looking for another to do.


Perhaps a patch over an existing, useless cog verb that would let you call these functions outside of cog would be good.
Air Master 3D (my iPhone game)
My Programming Website

↑ Up to the top!