# When the Dust hits the Fan

When the dust hits the fan

Why is the CPU fan running at top speed almost constantly?
Well, it’s 30 degree Celsius, what do you expect?

# Multi-Precision Floats: Radix Conversion with Large Exponents

[UPDATE] bugfix in code listing
The method for the radix conversion of floating point numbers described more theoretically here and more practically here has one large drawback: albeit always correct it is abysmally slow for large magnitudes.

Is there a faster way to do it? Yes, there is! Continue reading

# Adventures of a Programmer: Parser Writing Peril XXXX

The final[1] grammar together with the lexer. The whole file with a lot of comments is on Github. It is currently in one file for convenience but needs to be split into a lexer (Flex) and a parser (Bison) later.

The file has a lot of comments already, not much to say here, but nevertheless… Continue reading

# Computation of the Arcsin/Arccos

The MacLaurin (Taylor series at x=0) series for the arcsin

${\displaystyle{ \arcsin(x) = \sum_{k=0}^{\infty} \frac{(2k-1)!{\kern-1.25pt}!}{(2k)!{\kern-1.25pt}!} \frac{x^{2k+1}}{2k+1} }}$

is a very slowly converging one, especially close to the branchpoints at -1 and 1.
The MacLaurin series for arccos is the same as for arcsin because of

${\displaystyle{ \arccos x = \frac{\pi}{2} - \arcsin x }}$

so it has the very same problem.

The series for the arctan on the other side is simpler to compute.
Another good reason: I have it already implemented 😉

The arcsin is related to the atan by

${\displaystyle{ \arcsin x = 2\arctan\biggl(\frac{x}{1 + \sqrt{1 - x^2} } \biggr) }}$

which seems to be of no help at all because the fraction does not get very small and the series for atan is also quite slow near -1 and 1. We can use another relation for this range.

${\displaystyle{ \arcsin x = \mathop{\mathrm{sgn}}(x)\arctan\Biggl(\sqrt{\frac{x^2}{1 - x^2 }} \Biggr) }}$

Seems not of much use but we can expand the root

${\displaystyle{ \arcsin x = \mathop{\mathrm{sgn}}(x)\arctan\biggl(\frac{x}{\sqrt{1 - x^2 }} \biggr) }}$

The closer x comes to the branchpoint the larger the fraction, but with

${\displaystyle{ \arctan x = \frac{\pi}{2} - \arctan \frac{1}{x} }}$

the actual value gets close to zero when x goes close to one and $\arctan 0 = 0$ so
$\arcsin 1 = \frac{\pi}{2}$ which is correct and as intended. The point where $\frac{x}{\sqrt{1 - x^2 }} = 1$ is at $x = \frac{1}{\sqrt{2}}$ and at this point $\arctan 1 = \arcsin \frac{1}{\sqrt{2}} = \frac{\pi}{4}$.

My cutoff points will be $\arcsin = 2\arctan \bigl(\frac{x}{1 + \sqrt{1 - x^2} } \bigr)$ for $|x| \le 0.8$ and $\arctan\bigl(\frac{x}{\sqrt{1 - x^2 }} \bigr)$ for $|x| > 0.8$.

No code yet, just twiddling with math, sorry 😉

For $x \in\mathbb{R} \land |x| > 1$ the real part of the result is always $\frac{\pi}{2}$ and the imaginary part $\mathop{\mathrm{sgn}}(z) \log\bigl(x + \sqrt{x^2-1}\bigr)$. This comes from one of the definitions

${\displaystyle{ \arcsin x = -i\log\biggl(ix + \sqrt{1 - x^2 }\biggr) }}$

I will use this definition for complex arguments.

# JavaScript: Make a Real typeof

The problems with JavaScript’s typeof operator are manifold. It is so restricted, that its only use is in testing for undefined. The main culprit cause these restrictions is the loose typing together with the automatic type coercion: "2" + 2 results in 22, "2" == 2 is true, t = 2;typeof t returns "number" and t = new Number(2);typeof t returns "object" to name just a few.
The worst case is probably:

// somewhere on top of the code
var a = 2;
// some thousand lines and/or several scripts later
var b = new Number(2);
if(a === b){
// CPR: Cardiopulmonary resuscitation
console.log("Go on with CPR!");
} else {

The Firefox browser has a little tool for JavaScript editing build-in called “scratchpad”. Based on the editor CodeMirror it is a bit better than writing a small HTML file with a textarea and a button to eval() the content but not very much.