Extremely Fast sine/cosine

?

I am curious as how to 12-bit without interpolation performs. :-*

12-bit interpolated: 4.43 ms
12-bit raw value: 3.31 ms

16-bit interpolated: 5.20 ms
16-bit raw value: 4.25 ms

I totally did not see that coming. Weird. I don’t think I got values like these earlier.

That’s for theagentd to ignore. For N objects he’s performing 2N forward trig ops per simulation step. The sim only requires two per step.

So given 3 values (x, y, time) I can compute sin(x+time) and sin(y+time) with a single trigonometry function?

sin(t+x) = cos(x)sin(t)+cos(t)sin(x)
sin(t+y) = cos(y)sin(t)+cos(t)sin(y)

per sim step is cos(t) & sin(t) which is really one trig op…not that it would matter.

{…cos(x),sin(x),cos(y),sin(y)…} packed array. Speculate loading and skips the trig table lookup. More accurate, but that probably doesn’t matter either. So 2x (2 look-up, 2 mul, 1 add) per entry.

Uhm, I simply use sin() to get a wavey motion. Each grass patch has a spring system, and the wind force calculation is based on a sinus function. There is no rotation here.

No you’re computing the y-component of two rotations.

EDIT: I’d expect the 2-fold symmetry to be obvious here.

EDIT 2: http://glslsandbox.com/e#28037.0

I should care… but your “explanation” is like the worst possible professors at my uni who supposedly know a lot about their topics but can’t teach for shit all combined into one. I can’t follow your reasoning and it’s too time consuming to decode your intentions. Sorry.

I said up front “for you to ignore”.

I explained nothing…there should be no need. Math transforms are legal or not. Identities are always legal. The math doesn’t care how you’re thinking about the input or output.

For the google impaired: https://en.wikipedia.org/wiki/List_of_trigonometric_identities#Angle_sum_and_difference_identities

Every expression on this page is always true (for real input).

Any legal interpretation you can place on a mathematical expression is always legal. Comparing two angles is always the same as comparing a point against a line through the origin. It may or may not be worthwhile to consider other interpretations…either it’s helpful in some way or it’s not. You brought up rotations, so yeah what you’re doing is related to rotations.

EDIT: Pictures!

This one’s slightly more fun:

They’re paid to help you. Any time I type in information here I’m putting my hand in my pocket and throwing cash out the window the entire time I’m typing. Seems pretty understandable that my willingness to do so is rather limited.

I don’t understand what you’re whining about. If you don’t understand what, say, fold-symmetry means and you care then starting typing in google…I just did that and even before I completed my typing some pictures where popping up. But you don’t even need to do that…I typed in a brute force shader (rather poor visualization, but good enough)…click on the link.

If you’re using trig and/or inverse trig functions at any high rate, it’s very likely you’re missing some mathematical property that makes them disappear. Using trig functions means you’re manipulating angles…and angle are generally not interesting for computation.

Offtopic:

Roquen, what kind of mobile plan are you on that you value terse descriptions over comprehensible descriptions. As I said before, you can be correct, but if you cannot convince, the effort is meaningless.

Most of us seem to take mobile bandwidth and online-time for granted. Surely it cannot be so expensive that you would handicap yourself like this.

Fiber to the house…unlimited on the phone. My time is the limiting factor. Like I’ve said before I expect people can ask a question if they don’t follow and/or can surf the web.

To decode this a bit for the people that are interested. I believe this is what Roquen is trying to say.

If you pre compute cos(x), sin(x), cos(y), sin(y) and save these values for each of the N objects you only need to compute sin(t) and cos(t) for each render cycle because these are the only variables that change. As you already have cos(x),sin(x),cos(y),sin(y) saved you just need to perform 4 multiplications and 2 additions per render cycle. Comparing both methods you get (Theagentd vs Roquen)

2N Lookups + 2N additions vs 4N multiplications + 2N Additions + 2 Lookups = 2N Lookups vs 4N Multiplications + 2 Lookups

Assuming multiplications are more than 2x quicker than lookups and N is sufficiently large you will save time using this method.

Hope this helps clears things up a bit

Thank you, that is a great idea. I will implement that.

@ziozio: The real difference is going to be in dependency chains. (for x only shown below)

Table look up requires a sequence of 6
x0 = read x
x1 = x0 + RegM
x2 = x1 * K
x3 = int(x2)
x4 = x3 & M
x5 = table[x4]

Using sum-of-angles requires 3:
x00 = read cos(x) | x01 = read sin(x)
x01 = x00RegM | x11 = x01RegN
x2 = x01+x11

@theagentd: the pre-computed sin/cos values have to be in an array. Perhaps using jitwatch and careful layout you could get the computation into SIMD (packed) ops.

Lol, you must be an economist as well as a mathematician and programmer!
As someone who obviously understand opportunity cost, do you contribute to open source software? A truly rational person would not, it seems, since it’s a complete waste of time. Yet may programmers do, for the fame, notoriety or feel-good emotion that they’re part of something bigger than themselves.
I’m not faulting you and I appreciate your maths posts and your humour, demonstrated here. I just wonder how you can justify your actions based solely on opportunity cost.

Indeed, money here really means opportunity cost. Personally I think it’s a good idea to periodically think about the opportunity cost associated with any decision you make and decide from there if it’s a good idea. If you spend (say) an hour doing A, that’s costing you two hours worth of doing B instead. (You change to doing B, after the first hour that’s how much of B you could have done if you had not done A. But you’re still one hour where would would have been if you hadn’t done A at all.)

And another thing to take into account is Hofstadter’s Law: It always takes longer than you expect, even when you take into account Hofstadter’s Law.

I used to quite a bit. I more or less stop for years when Richard Stallman adopted his “I’m a fucking idiot” public persona. I still refuse to contribute to any FSF licensed software (beyond bug reports). RS is really just the tip of the iceberg…I stopped and thought: I really don’t like any of these figurehead people and I don’t like how these communities are are attracting and promoting the creation of vocal dogmatic asses. Sure I know they are actually the minority, but I don’t care. (Oddly I just got a tweet to this: http://sarah.thesharps.us/2015/10/05/closing-a-door)

Not so much these days mostly because projects I’d be willing to contribute to are complex and I don’t have (or am unwilling to spend) the time to needed to understand the code base. Say LLVM or HotSpot.

Because opportunity cost isn’t the only consideration. Another other important economic idea is utility. Which may or may not be utility for the person in question that’s spending their time. I don’t see any point in spending time typing up something where there are tons of resources on the subject. Like locally trig identities. On the other hand if I know of few to no resources on a particular topic I’m likely to write significantly more. Recent examples: looking at N-d problems in 2D if that’s the actual case. This information is scattered across different domains (I’m not aware of a single resource with this info). And inequalities. Time and time again I see very experience people missing some basic properties. The wikipedia page seems to me to be somewhat understandable…but it does not walk through how they are related which is important for real understanding.

Wow, I didn’t even see this until now. Is that a joke? I’m being serious. What do you even think the purpose of this forum is?

I use and enjoy this forum for a number of reasons. People make interesting things that inspire me. I can post about think I’ve coded that I’m proud of and get feedback and acknowledgement from people who actually understand and appreciate what I’m doing, which is a rarity IRL for me. I learn new things about math, HotSpot, LWJGL and uncountable other things all the time here. I can follow and discuss the development of things I admire or personally care about. Even just explaining things to others helps me get a better grasp of those concepts myself.

That being said, how do your posts fit into that? Although you seem to want to help, your answers are too brief and unexplained to help much without a direct neural link to your brain. Your explanations are like a summary of your knowledge that only someone with similar knowledge already would understand. What annoys me the most is that you just literally told me that your time is extremely valuable, yet you expect every single person who read (and actually want to understand) your comments to spend a significant amount of time Googling to decode your posts.

I think it’s sad, because if you’re half as knowledgeable as you claim seem to be then I have lots to learn from you. I may not be interested in learning everything (AKA advanced quaternion math), but we often comment in the same threads which means our interests do overlap. IMO the main point of this forum is sharing knowledge. Maybe you don’t think that you’re “receiving” as much as you’re “giving” to this forum since you already know a lot, but there are lots of other points that even it out IMO. It’s not a zero-sum game.

Sorry for the off-topic post…

EDIT: claim —> seem

Whatever you can make of it.

This is worth pointing at…talking through stuff with someone often help clarify things to yourself.

Everybody’s time is valuable that’s the whole point of opportunity cost vs. utility comments above.

Or simply post: can you explain this? Look above I talk about dependency chains. Explaining that for the widest audience would require giving a complete overview of how modern CPUs work. Or dig up a bunch of URLs for people to wade through.

I don’t recall making such a claim.

That’s part of my point in being terse, there’s no point is spending time on something if nobody’s interested.

EDIT: Hit post instead of preview.

I like @Roquen’s posts… it’s like trying to do a cryptic crossword. Unfortunately 90% of what Roquen says is founded upon a huge chunk of basic mathematical and comp sci knowledge and wisdom which I don’t have, so I am frequently completely in the dark about many assumptions that are made.

Now… I’ve got 35 years programming experience, 22 of which professional, and a honours comp sci degree, and even a Maths A level, but as I say… most of this stuff appears to be based on top of some foundation which appears not to have featured in either my admittedly wasted education or admittedly pragmatic experience. I would say that for the large majority of readers, they’re in the same or worse states of understanding than I am, as many of 'em are half my age. When @theagentd or @Riven don’t know what Roquen’s on about though I know we’re doomed, because they’re amongst the two most intelligent people on the board.

All of which brings me to thinking that… it is possible that to save endless repeated terse and cryptic explanations (wasting your time even further) it might be ultimately more efficient to be more pragmatic and straightforward in approach to teaching us ignoramuses your wisdom.

Cas :slight_smile: