14 ms·
Float Toy
- Taniwha 4y agoCool - thanks! - just started work on an FPU .... would prefer it of the bits were numbered from 0 though
- barbito 4y agoDuring my research projects I used this website incredibly often. I even cited it in one of my papers :)
- askafriend 4y agoFun fact, this site is from the co-founder of Figma.
- wyldfire 4y agoMight be worth an explicit link to an example illustrating subnormals [1] - they seem to be one of the not-well-understood features of floating-point. [1] https://en.wikipedia.org/wiki/Subnormal_number https://en.wikipedia.org/wiki/Subnormal_number
- naillo 4y agoMakes me think of this https://float.exposed/ https://float.exposed/
- bobek 4y agoAlso vaguely relevant https://0.30000000000000004.com/ https://0.30000000000000004.com/
- dwaite 4y agoRepresenting 1/10 with fractional powers of two is an infinite series, so tenth of a whole number will not be exactly representable with IEEE floating point. In financial apps, it is perhaps more common to use specific numerical types that don't lose precision. One simplistic option is to simply represent the smallest unit (say, tenths of a penny) with a fixed point number rather than a unit like USD dollars in floating point.
- tialaramex 4y agoIt's interesting today to see people act as though half (f16) is a completely normal obvious type, whereas when I was first writing code nobody had this type, it was unheard of, and it was this weird new special case when the 3DFX Voodoo used it (hardware accelerated 3D video for the PC, as a special case, the "pass through" for 2D video is a physical cable at first). The give away, if you're younger, is that it's sometimes called half precision. That's because single precision (32-bit floating point) was seen as the starting point years before. I remember this when somebody says f128 will never be a thing, because if you'd asked me in 1990 whether f16 will be a thing I'd have laughed. What use is a 16-bit floating point number? It's not precise enough to be much use in the narrow range it can represent at all. In hindsight the application is obvious of course, but that's hindsight for you.
- djhaskin987 4y agoI still don't see the point of half precision. What applications are you implying are obvious? Actually curious.
- Stratoscope 4y agoThere is a good discussion and examples here: https://en.wikipedia.org/wiki/Half-precision_floating-point_format https://en.wikipedia.org/wiki/Half-precision_floating-point_...
- mysterydip 4y agoMakes me wonder if there's a use case for "dynamic fixed point" numbers: say for a 16 bit value the upper 2 bits are one of four values that says where the decimal is in the remaining 14. Say 0 (essentially an int), two spots in the middle, and 14 (all decimal). The CPU arithmetic for any operation is (bitshift+math), which should be an order faster than any float operation. The range isn't nearly as dynamic, but would allow for fractional influence. Maybe such a system would lack enough precision for accuracy?
- 4y ago
- monkeydom 4y agoAlso see https://float.exposed/0x44bf9400 https://float.exposed/0x44bf9400 by the great ciechanowski, with a lengthy article here: https://ciechanow.ski/exposing-floating-point/ https://ciechanow.ski/exposing-floating-point/
- quickthrower2 4y agoIs that the man who did the introduction to category theory for programmers. Although I never grokked it as much as I would like, I appreciated that video series, for trying to make the subject so accessible.
- amelius 4y agoIt has a hidden UI trick: click+drag over the digits to turn them all to 0 or 1.
- seanalltogether 4y agoOne thing that took me a long time to grok that I wish this toy showed is how the fraction is included in the calculation underneath. Right now the following bits 0 10001 1000000000 show the calculation as 1 x 2^2 x 1.5 = 6 when it's more clear to actually say 1 x 2^2 x (1 + (512 / 1024)) = 6
- TT-392 4y agoI had to implement floats and doubles a bit ago. Was a fun bit of puzzling to figure that out as a small break from other work.
- TT-392 4y agoThen I found out about weird poorly defined NaNs, which were kinda annoying, but fun nonetheless.
- quickthrower2 4y agoI didn't know different binary numbers could map to NaN. That is interesting.
- brrrrrm 4y agoa popular trick is to encode information in NaNs
- cercatrova 4y agoAh Evan Wallace, the creator of esbuild, CTO of Figma, and maker of one of my favorite tools, Diskitude [0] which shows disk space usage on Windows, all under 10 kilobytes. [0] https://madebyevan.com/diskitude/ https://madebyevan.com/diskitude/
- NavinF 4y agoLooks like this does not read the MFT. So I’d expect it to take minutes instead of seconds to scan a typical 2TB SSD.
- cercatrova 4y agoLooks like you're right. Any tools you know that do?
- olliej 4y agoBoo, no fp80! Honestly I think having fp80 would be super interesting as it was the first end-user available hardware implementation of ieee definition of floating point, and also as a by product shows some design "mistakes" that were ironed out by the time fp32/64 were formalized.
- mikotodomo 4y agoThis is amazing. It really demonstrates how JavaScript is such an important technology. I can see some patterns already from playing with this, as someone without much math and CS knowledge.
- Sharlin 4y agoA while ago I realized that a very fast way to multiply or divide a 32-bit float by 2^n is to simply reinterpret it as int and add/subtract n<<23. Plus some checks if you care about overflow. Obvious in retrospect, and may not be worth it on modern desktop hardware, but still a nice trick. (This was in the context of optimizing a texture sampler for power-of-two textures.)
- alberth 4y agoYou can do lots of interesting things with bit shifts. Like the famous Quake3 Fast Inverse Square https://www.beyond3d.com/content/articles/8/ https://www.beyond3d.com/content/articles/8/
- ChrisLomont 4y agoPlenty of languages have this in their standard libraries for exactly this purpose. I use it in C/C++ and C# frequently in numerical code.
- Sharlin 4y agoOh wow, I had totally missed that C has such functions as `ldexp` and `scalb*`.
- adgjlsfhk1 4y agoOne place where this is used in practice is in the code to compute floating point exponentials.