10 ms·
The Floppy Disk of Floating Point
- gweinberg 6y ago"There’s even FYL2XP1, for all those occasions when you need to compute ylog2(x+1) on the double" When would I want to do that?
- nraynaud 6y ago“ The (ε+1) expression is commonly found in compound interest and annuity calculations. The result can be simply converted into a value in another logarithm base by including a scale factor in the ST(1) source operand.” https://www.felixcloutier.com/x86/fyl2xp1 https://www.felixcloutier.com/x86/fyl2xp1
- beckerdo 6y agoA good article. However the real floppy disk is the floating point standard . These days other number representation are exceeding floating point in terms of dynamic range, flexibility, fewer exception cases, better rounding, and cheaper/faster hardware implementations. Read about Unum computing, pioneered by John Gustafson, and implemented on many modern software and hardware platforms. https://en.wikipedia.org/wiki/Unum_(number_format) https://en.wikipedia.org/wiki/Unum_(number_format)
- userbinator 6y agoThe x87 FPU finds an interesting niche application in size-optimised demoscene productions, where the stack-based architecture and scientific-calculator operations allows for some impressively compact 3D demo effects. For example, this one is 256 bytes: http://www.pouet.net/prod.php?which=53816 http://www.pouet.net/prod.php?which=53816
- vardump 6y agoSolar system scale 128-bit floats can be useful for storing coordinates. Any other reasons to go beyond 64 (or 80) bits?
- fanf2 6y agoBabbage's Difference Engine Number 2 has 31 digits of precision (about 103 bits), but it is fixed point rather than floating point. https://en.wikipedia.org/wiki/Difference_engine https://en.wikipedia.org/wiki/Difference_engine
- 082349872349872 6y agoI have a book somewhere in the basement on organising calculations from the early twentieth century, back when computer was a job title and job runtime was measured in weeks... ===Update=== Couldn't find the one I was looking for, but I did dig up Eckert, Punched Card Methods in Scientific Computation (1940). From Chapter VII "The Multiplication of Series": p.68 "By a continuation of this process we obtain about 100 groups of cards each with its rate card. Since the capacity of the multiplier is eight digits, those groups which have 9 and 10 digit multipliers and eight digit multiplicand are done in two groups. The few terms with large multiplier and multiplicand are done by hand. In a series with reasonable convergence there may be about 20,000 cards altogether. The reproducer is of course used to check the punching." 10 decimal digits is what, 33 bits? p.74 "The machine time for 100 series is as follows: Original punching and verifying . . . . 2 days Listing and summary punching checksums. 1/4 day Sorting and gang punching duplicates. . 1 day Multiplying . . . . . . . . . . . . . . 1 day Sorting, tabulating, and summary punch. 1 day In this example the checks would have been exact had we included a card for each product regardless of size, but this would have required about forty thousand cards instead of four or five thousand, and the multiplying time would have been over a week instead of one day." I guess in principle a punched card could have contained 80 decimal places, but it seemed like the ALU equivalents were much narrower. (this was published by the Thomas J. Watson Astronomical Computing Bureau)
- deleted 6y ago[deleted]
- v-yadli 6y agoThe system will also be more tolerant for ill-formed numbers, and thus numerically more stable (not running into NAN / INF as frequently).
- mayoff 6y ago> You’ll find F2XM1, which computes in a swoop (2𝑥−1) – a kind of pauper’s fused multiply-add, some twenty-five years ahead of its time. No. It computes pow(2, x) - 1. Suppose x is close to 0, so that pow(2, x) is close to 1, like 1.00000000000000002345678. Because of that leading 1 (to the left of the radix point), all those zeros also have to be stored, meaning some of the low-end digits will have to be dropped, so you end up rounding to 1.00000000000000002. But if you can subtract 1 from the exact result before rounding, then you can store more of the low-end digits: 2.345678e-18. Hence the F2XM1 instruction.
- lalaland1125 6y agoexpm1 is the modern equivalent. That (plus the related log1p) are probably some of the most underutilized standard library math functions. They can substantially improve the accuracy of tons of calculations.
- nwallin 6y agoCan you give an example of a common situation where a programmer should have used expm1 or log1p but didn't? (the way it's common for people to test if something is inside/outside a circle or sphere by comparing the square root of the sum of squares to the radius as opposed to compare the sum of squares to the square of the radius, or use trig functions when linear algebra will do) I do a reasonable amount of computational programming but to my recollection I've never used either of those functions.
- lalaland1125 6y agoOne common situation is when evaluating CDFs for exponential or weibull probability distributions. The CDF formula for both of those distributions includes a 1 - e^(x) term that can easily be transformed into expm1 for additional precision.
- saagarjha 6y agoOne example I can think of is doing an interest calculation with small interest rates/short periods, where you'd want to know that someone owes you 0.000000001234 dollars in interest today rather than owing you 1.000000001 - 1 dollars.
- msspecter 6y agoI have a feeling that Kahan lived in a time where matrix inversion and eigenvalue computation was considered the new hotness, just like neural networks today. It is very easy to build small invertible matrices that cannot be inverted with 32-bit floats, or even 64-bit floats, thus Kahan's insistence on very high precision floating points. Edit: small invertible matrices
- gspr 6y agoI assume you mean small invertible matrices that cannot be inverted with …
- jey 6y ago> small matrices that cannot be inverted with 32-bit floats, or even 64-bit floats Presumably these all have eigenvalues near zero and away from zero (i.e. the condition number is large)?
- the_svd_doctor 6y agoYes. Ill conditioned matrices are hard to “invert” (more like solve Ax=b for a given A and b) almost by definition. The condition number is basically a measure if sensitivity. If I change b a little, the change in x is proportional to b multiplied by the condition number. If the matrix is very ill conditioned (say more than 1e10 for a double precision algorithm), the matrix is really singular for any practical purpose, so the problem is really ill posed.
- msspecter 6y agohttps://en.wikipedia.org/wiki/Hilbert_matrix https://en.wikipedia.org/wiki/Hilbert_matrix "The Hilbert matrices are canonical examples of ill-conditioned matrices, being notoriously difficult to use in numerical computation."
- everybodyknows 6y ago>lived The man lives still, not to be numbered among the dead: https://en.m.wikipedia.org/wiki/William_Kahan https://en.m.wikipedia.org/wiki/William_Kahan
- mmphosis 6y agohttps://en.wikipedia.org/wiki/Unum_(number_format) https://en.wikipedia.org/wiki/Unum_(number_format)
- layoutIfNeeded 6y agoI hope my new Mill CPU will natively support Unums. And the whole thing should be memristor-based of course, running on carbon nanotube batteries.
- klodolph 6y ago> ...a kind of pauper’s fused multiply-add, some twenty-five years ahead of its time. Maybe 12 years. The PowerPC had fused multiply-add in 1992. For whatever reason, it didn't really appear in x86 until 2012.
- jacquesm 6y agoAnd many DSPs had it long before then.
- Someone 6y agohttps://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format#Hardware_support https://en.wikipedia.org/wiki/Quadruple-precision_floating-p... shows (non IEEE) 128-bit floats existed in the 1970s, and that IEEE ones were added to Power in 2015, and the clang, gcc and Intel C compilers support them in software. There clearly is a market for them. Truth is that successive rounding errors accumulate complex calculations can lose a lot of bits of precision. That’s why you sometimes need to do calculations in a lot more bits than needed in the answer. Also, the x87 had 80 bits floats, but not all instructions computed all of them correctly (https://www.infania.net/misc/coproc.html https://www.infania.net/misc/coproc.html) I don’t know how current FPUs fare there, but would hope they have become optimal.
- acqq 6y ago> but not all instructions computed all of them correctly (https://www.infania.net/misc/coproc.html https://www.infania.net/misc/coproc.html) I failed to find which instructions weren't computed correctly in the text linked, and I'd like to know about that, that is, if it's something I wasn't aware of. Can you specify a bit more?
- Someone 6y agoSearch for “Accuracy of calculations performed by a coprocessor” in the article I linked to. it says “Intel claims that maximum error in the 8087, 80287, and 80387 for all transcendental functions does not exceed two bits in the mantissa of the double extended format”. Typically, those reposts get rounded to double format, but that doesn’t guarantee that such errors get dropped. Edit: http://www.math.utah.edu/~beebe/software/ieee/ http://www.math.utah.edu/~beebe/software/ieee/ has lots of links and code for testing floats. http://li.mit.edu/Archive/Activities/Archive/CourseWork/Ju_Li/MITCourses/18.335/Doc/IEEE754/ieee754.pdf http://li.mit.edu/Archive/Activities/Archive/CourseWork/Ju_L... gives quite a few corner cases, so it would be helpful when writing a test suite. https://slixe.de/stash/projects/MAS/repos/libfirm/browse/ir/tv/IeeeCC754?at=8045fb7fc4f9dc8c0ae329e17b78d5fc2d679517 https://slixe.de/stash/projects/MAS/repos/libfirm/browse/ir/... has source code for a/the compliance checker https://core.ac.uk/download/pdf/151193633.pdf https://core.ac.uk/download/pdf/151193633.pdf describes what seems to be a Better version of that test framework (it adds “++” to the name). Unfortunately I couldn’t find its source code.
- everybodyknows 6y ago> Professor Kahan was last seen ranting about benchmarks. Incorrect. Scroll to the bottom of this page to find works dated 2016: https://people.eecs.berkeley.edu/~wkahan/ https://people.eecs.berkeley.edu/~wkahan/
- simonbyrne 6y agoOne of the interesting things about the 80-bit format was that allowed the use of 64-bit integers on a 16 or 32-bit machine. This was what Thomas Nicely was using them for when he found the Pentium FDIV bug: https://faculty.lynchburg.edu/~nicely/pentbug/pentbug.html https://faculty.lynchburg.edu/~nicely/pentbug/pentbug.html
- microtherion 6y agoOne problem with x87 is that it performed all operations in 80 bits, converting to float and double on load/store. This sounds nice, but in practice was quite problematic, as results depended on whether or not intermediate results spilled into memory.
- WalterBright 6y agoI'm sad to see the x87 go. I've never been able to convince anyone of the value of 80 bits of precision. Never mind that I've seen engineers convinced their sums were correct (because the computer can't be wrong) because they used insufficient precision for adding too many numbers. But you can thank (or blame!) me for extending its life - back when Microsoft was developing their 64 bit Windows, they were all set to not save the x87 state during a context switch, effectively killing the x87. I talked them out of it. Microsoft's VC still doesn't support the x87, their "long double" is 64 bits. I suppose that's for compatibility with other processors it supports. I'm proud of the Digital Mars C/C++ compiler which still sports full 80 bit long doubles, as well as the D programming language which still (despite opposition) delivers 80 bit precision for type real, even for 64 bit Windows.
- rwallace 6y ago> back when Microsoft was developing their 32 bit Windows, they were all set to not save the x87 state during a context switch, effectively killing the x87 Do you mean '64-bit Windows'? (When 32-bit Windows was being developed, killing x87 would have meant killing all hardware floating point on x86.)
- WalterBright 6y agoyes, 64-bit
- dang 6y agoI edited that now. Hope that's ok.
- WalterBright 6y agoedit: Microsoft was developing their 64 bit Windows
- dang 6y agoI've doubled the 32 in your original comment. Hope that's ok.