Sunday, 15 April 2007

All Will Turn Out Fine

This year I'm going to write music again. I thought I'd start by pulling out all the songs I'd ever written, and putting them all together. Below is the lyrics to the one I'm working on recording now.

All Will Turn Out Fine
© Paul Mulroney 1996

V1
Sometimes I wonder if I’ll ever make the grade
Someday, somehow, I won’t be afraid
To walk by faith and not hold back
Whatever, come what may
Someday, somehow, I won’t be afraid

Ch
I see the Then and don’t know When
All this dreamin’s for
I see the signs and don’t know Why
Heaven seems so far
I see the Now and don’t know How
In all of these dark and troubled times
That all will turn out, all will turn out
All will turn out fine

V2
It seems the road I’ve set upon has dangers by the way
Someday, somehow, I will find the way
They beckon with their false perfume and lead so far away
Someday, somehow, I will find the way

Ch

V3
I hear a soft familiar voice cry gently on the wind
Someday, somehow, I’ll find my rest in Him
Resting in my Saviour’s arms I know I’ll finally win
That day, somehow, I’ll have my rest in Him

Ch
I’ll see the Then and I’ll know When
All this dreamin’s for
I’ll see the signs and I’ll know Why
Heaven seemed so far
I’ll see the Now and I’ll know How
In all of those dark and troubled times
That all has turned out, all could turn out
All has turned out fine

Saturday, 14 April 2007

Magical Square Root Implementation In Quake III

One of the sites I regularly read is Worse Than Failure which looks at bizarre bits of code that programmers come across from time to time. (It used to be called WTF, short for "What the F...???", something that Rove has shortened to "What the?" and made a regular segment in his TV show.)

In the comments of one of the recent articles was this code snippet to calculate the square root of a number, which was originally written for Quake III.

float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;

x2 = number * 0.5F;
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the f...?
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed

#ifndef Q3_VM
#ifdef __linux__
assert( !isnan(y) ); // bk010122 - FPE?
#endif
#endif
return y;
}
Try Goolging 0x5f3759df and you'll find lots of references. It turns out that the above routine implements a theory called Newton Approximation of roots. The square root of a number can be approximated using a certain calculation, and can be refined by repeating using the results of the previous calculation. The tricky part is the magic number, which generates an initial result which is very close to the actual result, good enough for the purpose.

John Carmack is the programmer who wrote this piece of code. A genius indeed.

Very cool.

Thursday, 12 April 2007

The Ashes

We were talking about cricket the other day, and the question of The Ashes came up. I had heard a long time ago that The Ashes came about because of a crushing defeat of England at the hand of the Aussies, and someone had presented to the Aussies an urn which contained the ashes of the cricket stumps from the match.

Wikipedia says:

The Ashes is a Test cricket series, played between England and Australia - it is international cricket's most celebrated rivalry and dates back to 1882. It is currently played nominally biennially, alternately in England and Australia.

The series is named after a satirical obituary published in an English newspaper, The Sporting Times, in 1882 after the match at The Oval in which Australia beat England on an English ground for the first time. The obituary stated that English cricket had died, and the body will be cremated and the ashes taken to Australia. The English media then dubbed the next English tour to Australia (1882-83) as the quest to regain The Ashes.

During that tour in Australia, a small terracotta urn was presented as a gift to the England captain Ivo Bligh by a group of Melbourne women. The contents of the urn are reputed to be the ashes of an item of cricket equipment, possibly a bail, ball or stump. The urn is erroneously believed, by some, to be the trophy of the Ashes series but it has never been formally adopted as such and Ivo Bligh always considered it to be a personal gift.



While I was looking for related articles, I came across this flash-based game of cricket. Enjoy.