Tech

Why programmers are ditching radians for turns to boost code precision

A new technical analysis suggests that replacing radians with turns in trigonometric functions can simplify code, improve speed, and eliminate unnecessary computational overhead.

Editorial persona
Owen Mercer
Markets and Finance Editor
Published
Draft
Source: Hacker News · View original source
Tech
No image available
Technology

A technical article published on Computer Enhance argues that using turns instead of radians simplifies code, improves speed, and increases precision in programming. The author contends that converting values to radians for trigonometric functions introduces unnecessary computational overhead and precision errors, as libraries often immediately convert back from radians.

The piece suggests that parameterising angles on a [0, 1] scale (turns) or [0, 2] scale (half-turns) allows for exact representation of common angles and eliminates the need for pi and tau constants in many codebases. The author notes that common angles like 90 degrees are inexact in radians but exact in turns (0.25), offering better precision and compactness.

To demonstrate the redundancy of radian conversion, the article cites the Godot Engine source code and AVX2 implementations of sine functions. It shows that radians are often converted back to a [0, 1] domain internally, making the initial conversion by the programmer redundant. The author argues that this results in a "conversion to radians and back for no reason," where the calling code multiplies by a factor of pi just so the library code can immediately divide it back out again.

The concept of a "turn" is described as a legitimate mathematical construct where 0 is 0 degrees, 0.5 is 180 degrees, and 1 is 360 degrees. The article acknowledges previous efforts to replace approximations of "pi" with "tau" to simplify formulas, but considers that a minor point compared to the opportunity to remove pi entirely.

For developers who do not wish to modify their own math libraries, the article highlights that some existing libraries, such as CUDA's sincospi intrinsic, already support half-turns. This allows developers to stop using pi and tau constants without modifying their libraries, simply by calling the intrinsic with half-turns instead of radians.

The author claims that having managed entire codebases where radians were stopped, they never miss them, noting that superfluous constants disappear and code reads more clearly. However, the assertion that switching to turns makes code faster depends on the specific implementation and whether the library already optimises for non-radian inputs, with real-world performance gains potentially varying.

Continue reading

More from Tech

Read next: Microsoft revises Windows 95 packaging hologram after government complaint
Read next: The red Tetris sticker on Microsoft Entertainment Pack: A licensing contingency
Read next: Gardner City Council scraps Flock Safety cameras over privacy concerns