Damus

Recent Notes

Wolf480pl · 3d
nostr:nprofile1qy2hwumn8ghj7un9d3shjtnyd968gmewwp6kyqpqpu3ryltaaqjym9gj5fpcv623edtfh2vuvrtcd8pz75p6nlyt0nrqwf22w0 gimme a sec
Fabian Giesen profile picture
There's this observation that the volume of unit-radius hyperspheres gets tiny as dimension increases, and also the famous example where you place unit spheres at the vertices (+-1, +-1, ..., +1) of a d-dimensional hypercube, put a sphere at the origin and see how big you can make it until it touches the corner spheres. (Spoiler: as d increases, very big indeed.)

Sometimes this is framed as "d-dim hyperspheres are just weird". They're not.

Hypercubes are the weird ones.
Shane Celis · 1w
nostr:nprofile1qy2hwumn8ghj7un9d3shjtnyd968gmewwp6kyqpqpu3ryltaaqjym9gj5fpcv623edtfh2vuvrtcd8pz75p6nlyt0nrqwf22w0 nostr:nprofile1qy2hwumn8ghj7un9d3shjtnyd968gmewwp6kyqpq6qmlxsjk0mwtch4sq6wkstgnsmat86dxzw2l4lp7t073z0sfpfes6nlwq4 I tried TC after MHRD and it seemed fine but then there was a bug that h...
Fabian Giesen · 1w
Although the original thing never got published, a different paper analyzing the algorithm (and confirming it gives correctly rounded results) was, in 1992: https://bpb-us-e1.wpmucdn.com/websites.uta....
Fabian Giesen profile picture
Anyway, if the idea of a floating-point computation ultimately unwrapping the float bits and doing a bunch of integer shifts and adds on them blows your mind, buckle up! You're not gonna believe how your FPU does FP additions, subtractions, multiplications and divisions either!

(and, yes, square roots)

This is not meant in a condescending way. I heartily recommend everyone with an interest in the topic check out how FP works under the hood. There's too much "a wizard did it!!!" going around
Fabian Giesen · 1w
That paper was concerned with doubles and getting the initial approximation to slightly under 8 bits was sufficient to get a correctly rounded double sqrt within 3 iterations. Tweaking the magic valu...
Fabian Giesen profile picture
Although the original thing never got published, a different paper analyzing the algorithm (and confirming it gives correctly rounded results) was, in 1992: https://bpb-us-e1.wpmucdn.com/websites.uta.edu/dist/7/5059/files/2021/06/csd-94-850.pdf

it also gives more of an explanation why it works, the original Kahan/Ng paper just assumes you're familiar with how IEEE floats are constructed and expects you to keep up. :)
1
Fabian Giesen · 1w
Anyway, if the idea of a floating-point computation ultimately unwrapping the float bits and doing a bunch of integer shifts and adds on them blows your mind, buckle up! You're not gonna believe how your FPU does FP additions, subtractions, multiplications and divisions either! (and, yes, square ro...
Fabian Giesen · 1w
That paper was never formally published (that I can track down anyhow) but note it has both regular and reciprocal square root versions (the latter on the way to computing a square root) as well as in...
Fabian Giesen profile picture
That paper was concerned with doubles and getting the initial approximation to slightly under 8 bits was sufficient to get a correctly rounded double sqrt within 3 iterations.

Tweaking the magic value to get rid of the initial LUT altogether is reasonable for float32, for the correctly rounded float64 sqrt-from-rsqrt they cared about it would've needed an extra iter which they tried to avoid.
1
Fabian Giesen · 1w
Although the original thing never got published, a different paper analyzing the algorithm (and confirming it gives correctly rounded results) was, in 1992: https://bpb-us-e1.wpmucdn.com/websites.uta.edu/dist/7/5059/files/2021/06/csd-94-850.pdf it also gives more of an explanation why it works, the...
Fabian Giesen · 1w
OK everyone on here and following me probably already knows this but I want to get it off my chest anyway: *please* stop attributing reciprocal-square-root-by-IEEE-bit-twiddling to John Carmack/Quake...
Fabian Giesen profile picture
That paper was never formally published (that I can track down anyhow) but note it has both regular and reciprocal square root versions (the latter on the way to computing a square root) as well as instructions for getting correctly rounded (=equivalent to doing the calculation exactly then rounding in active rounding mode) results.

That paper was 1986.

The only thing that ever changes is the exact choice of magic number constant; the paper didn't sweat it because it used a 64-entry LUT.
1
Fabian Giesen · 1w
That paper was concerned with doubles and getting the initial approximation to slightly under 8 bits was sufficient to get a correctly rounded double sqrt within 3 iterations. Tweaking the magic value to get rid of the initial LUT altogether is reasonable for float32, for the correctly rounded floa...
Fabian Giesen profile picture
OK everyone on here and following me probably already knows this but I want to get it off my chest anyway:

*please* stop attributing reciprocal-square-root-by-IEEE-bit-twiddling to John Carmack/Quake 3.

John has a lot of "firsts" under his belt but this is not one of them.

This trick is _old_. The magic constant changes, but the trick itself is _old_.

1993 versions of Sun's fdlibm already included this reproduction of W. Kahan and K. C. Ng's paper on the subject: https://github.com/freemint/fdlibm/blob/master/e_sqrt.c#L215
1
Fabian Giesen · 1w
That paper was never formally published (that I can track down anyhow) but note it has both regular and reciprocal square root versions (the latter on the way to computing a square root) as well as instructions for getting correctly rounded (=equivalent to doing the calculation exactly then rounding...