I recently posted articles on memoization of factorials and calculating sines and cosines with Taylor polynomials. It seems logical to combine the two principles and write a library to memoize the trigonometric values sine, cosine and tangent.
If you just need a few values then this approach is overkill, but some applications require very heavy use of trigonometry and so need all the optimization they can get. In particular 3D graphics consist of large numbers of triangles, the positioning and rendering of which requires some serious use of trigonometry.
In this post I will write a C library to calculate sines and cosines using Taylor polynomials. It is impossible to calculate these directly but they can be approximated to any accuracy using this method, and I will show how a Taylor series converges to ever-increasing accuracy.
I am currently working on an article about calculating sines and cosines using Taylor Polynomials. These make heavy use of factorials so I started thinking about ways to streamline the process.
This post consists of a simple project using memoization with a lookup table to pre-calculate factorials and store them for future use.
I recently wrote an article on Bubble Sort, more as an academic exercise than a piece of practical and usable code. At the bottom of the post I suggested that the C library’s built-in qsort (Quicksort) function was the best option for sorting arrays in most situations.
However, there is more to using qsort than just throwing an array at a function: you need to provide your own comparator function, the implementation of which can be slightly fiddly if you are sorting anything other than primitive data types. In this article I’ll start off with a simple int-sorting example, and then go on to sort an array of structs, firstly by an int and then by a string.