Live data from Hacker News

Turns are better than radians

computerenhance.com

341–350 of 494 posts

Re: Turns are better than radians

#341

Better than turns, radians, etc. is an `Angle` newtype AKA wrapper class. It completely eliminates misinterpretation of the value, miscalculation from [angle = angle + tau*n] as all angles are normalized, is more descriptive, and in a decent language is zero-cost. Programmers should not be using (radians: float) in modern languages which support wrapper classes

This has nothing to do with the article, and it is equally applicable to degrees, radians, or turns. It neither solves nor hinders the simplicity or performance issues the article was talking about.

I disagree. By wrapping an angle in an Angle class, the internal representation need never be exposed to the programmer.

Rather than every programmer needing to read this blog post to see the performance benefits of using 'turns', instead now just a few library developers need to.

Re: Turns are better than radians

#342
post #265

Earlier quoted context omitted.

The situation is similar to that of the logarithm and exponential functions[0]. There’s a log2 function and a log10 function and they are both useful. But when we talk about the log() function there can be no doubt that it is to base e. If you want to define a sinT() function that works in turns then that’s totally fine. But the sin() function is defined as taking an argument scaled in radians, because it is mathemat…

The sine function, defined as x-x^3/3!+... doesn't take argument scaled in radians. It takes real numbers. It has nothing to do with radians, really. Or even with angles. The other sine function, defined using right triangles takes argument in Angles, also has nothing to do with the measuring unit. (Also I don't know who told you that log() denotes log_e. Maybe in your narrow environment, but definitely not universal…

> The sine function, defined as x-x^3/3!+... doesn't take argument scaled in radians. It takes real numbers. It has nothing to do with radians, really. Or even with angles.

The point is that a definition of the sine function where sin(pi/2) = 1 is equivalent to a sine function taking radians.

You could also define sinT(x) such that sinT(1/4) = 1: sinT(x) = sin(2pi x) = sin (tau x) = 2pi * x - (8pi^3 * x^3) / 3! + [...]. Neither of these is more or less fundamental than the other, but one is more convenient in most (non-trig) calculations.

Re: Turns are better than radians

#343
post #329
post #265

Earlier quoted context omitted.

The sine function, defined as x-x^3/3!+... doesn't take argument scaled in radians. It takes real numbers. It has nothing to do with radians, really. Or even with angles. The other sine function, defined using right triangles takes argument in Angles, also has nothing to do with the measuring unit. (Also I don't know who told you that log() denotes log_e. Maybe in your narrow environment, but definitely not universal…

"Also I don't know who told you that log() denotes log_e. Maybe in your narrow environment," e.g. https://reference.wolfram.com/language/ref/Log.html But I must confess that we had ln() in university courses and by default log used base 10. Now I use ln and a base for the log as a subscript like log_10, log_2, etc.

Srsly? Well, then according to https://en.wikipedia.org/wiki/Brainfuck the + symbol denotes cell increment and not addition.

> But I must confess that we had ln() in university courses

Same. I often wonder why would anyone denote the natural logarithm with log(), when ln is shorter, and easier to read (at least for the people that were thought to use it), also it is already somewhat established.

Re: Turns are better than radians

#344
Who cares? It doesn't matter. No one doing serious work in physics, simulation, etc cares about units at all besides very broad distinctions between systems like natural units vs constructed. Arguing about imperial, metric, pi, tau, etc is 99% bikeshedding by people who don't even do this stuff.

> But math never decreed that sine and cosine have to take radian arguments

Yes it did. The lowest kolmogorov complexity definitions of all trigonometric functions (free from non-integer constants) all take radian-based arguments.

Re: Turns are better than radians

#345

y’’ = -y Radians are God’s chosen angular unit. If you want to do mathematics, you have to use radians.

Because I didn't see it mentioned yet, this is the same feature that makes the small-angle approximation of sin elegant: sin(x) ≈ x .

With a sin designed for turns, that is just sin(x) ~= 2pi * x or tau * x. Slightly uglier, but still quite simple.

Re: Turns are better than radians

#346
post #18

> Some time ago, much effort was expended to convince people to replace approximations of “pi” (3.14159…) with approximations of “tau” (6. 28318…). IMO the effort was simply to replace the use of pi with the use of tau. What does approximation have to do with it?

The author is a software engineer and when he says "people", he implicitly means other software engineers. When he says "replace" he means in code, not in equations.

It's a general challenge of writing on the web that you don't know what context the author assumes and the author doesn't know what context the reader assumes.

In this case, the blog title "Computer, Enhance!" and the article subtitle "Switching away from radians makes code simpler, faster, and more precise." sends a pretty clear signal that this is about programming and not pure mathematics.

For any given article on the web, you can always generate valid criticisms based on the author assuming some context that may not be true for all possible readers. You can't say, "Ice cream is cold" without some commenter pointing out that you're doing a disservice to astronauts for whom ice cream is freeze dried and room temperature.

I find the best way to extract value from writing on the web is to simply try to understand the author's assumed context and go from there.

Re: Turns are better than radians

#347
post #344

Who cares? It doesn't matter. No one doing serious work in physics, simulation, etc cares about units at all besides very broad distinctions between systems like natural units vs constructed. Arguing about imperial, metric, pi, tau, etc is 99% bikeshedding by people who don't even do this stuff. > But math never decreed that sine and cosine have to take radian arguments Yes it did. The lowest kolmogorov complexity de…

Ooof, you're no true scotsmanning with that bikeshedding argument.

No one doing serious work in physics, simulation

Well, he is doing game engines, so you are right, it is not about "serious work in physics, simulation", it is about simplicity and performance in games.

Re: Turns are better than radians

#348

Earlier quoted context omitted.

sin(x) ~~ x only in radians, so honestly that's reason enough. Once in a while we get programmers wanting to disrupt mathematical notation for whatever reason... Worst I've seen so far was one arguing that equations should be written with long variable names (like in programming) instead of single letters and Greek letters. Using turns because it's a little easier in specific programming cases is just as short-sighte…

Those perfect radians use 2*pi, aka tau, though, a different math notation issue, where mathematicians have chosen the wrong option (imho) and a case for disrupting that part of math notation, to make radians easier to teach: 1/4th of a circle could be tau/4 radians, 1/8th could be tau/8, etc..., instead of confusing halved factors with radians expressed as amount of pi. Regarding long variable names: I'd rather have…

That is a completely different matter. The definition of sin/cos in radians doesn't change if you prefer to use 2 * pi or tau - it's still x - x^3/3! + [...]. sin(pi/2) = sin (tau/4) = 1.

Re: Turns are better than radians

#349

A motivation seems to be performance (avoiding useless multiplications followed by divisions by the same factor). I'm not sure that you really "pay" for these multiplications, with code optimization?

I strongly suspect that in most cases, yes, you do. The only time you wouldn't pay this cost is if the multiplication outside of the sin() call and the multiplication inside of it can be constant folded together. That requires the call to sin() to have its code inlined at the callsite. Given how large most sin() implementations are, I would be fairly surprised if it does get inlined.

The only way to answer this is to profile it and see.

Re: Turns are better than radians

#350

Radians are just half-turns, so we use turns either way. Some equations look better in turns and some in half-turns, but the math works fine either way. Instead to decide which is better think of how a new student might learn this intuitively: How far around is it? 2.5 turns. This is so much clearer than 5.0 half-turns. Turns a more clear. No one

[deleted]
Post reply on HN