1 hour ago · Science · hide · 0 comments

At the end of my post on how not to calculate cosine I said that the first step in calculating cosine, particularly cosine of a large number, would be to do range reduction. This post will present a simple range reduction method by Cody and Waite that is adequate for moderately large arguments. If you want to compute the sine or cosine of an angle x you could start by reducing x mod 2π since that would not change the result. However, accurately reducing a number mod 2π is not trivial; that’s why range reduction is an area of algorithm development. Range reduction mod π/2 Even better would be to reduce x mod π/2. Reducing to a smaller range means that power series method, and other methods such as rational approximation, will be more efficient. So suppose you can find an integer k such that x − k π/2 = y where 0 ≤ y ≤ π/2. Then sin(x) is ±sin(y) or ±cos(y), depending on k mod 4 equals 0, 1, 2, or 3. from math import * def reduced_sin(x, k): match k % 4: case 0: return sin(x) case 1:…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.