4 ms·
>run it twice, once rounding towards negative infinity, and once towards positive infinity, and see how different they are That's actually a good method that l
by ChrisLomont 4y ago
>run it twice, once rounding towards negative infinity, and once towards positive infinity, and see how different they are
That's actually a good method that lots of numerical analysts use. I think C99 has several rounding modes - I often have code that runs the same computation under each mode and look at what your doing.
>not all crappy code generates a wide window
True, often you need to find the values that make it puke. I think there was a paper recently on doing this automatically.... If I can refind it I'll post - it was cool stuff.
>students are only allowed to use single (32-bit) precision floats and operations
For stuff this small you can often brute force all values or at least all edge case values. I sometimes do the trick of converting 32 bit integers (watch out for weird C aliasing rules) to hit lots of numbers near precision edges and run them through, denormals, other edge cases, and pseudo-fuzz the results. This will sometimes turn up more.
If you teach, and have not worked through some numerical analysis books that provide good background for this stuff, read Goldberg's paper "What Every Computer Scientist Should Know About Floating-Point Arithmetic" [1]. The next good thing to dig through is Higham's book "Accuracy and Stability of Numerical Algorithms" [2]
Those will give you lots of places to look for issues, and the ability to analyze algorithms more concretely for floating point issues.
[1] https://docs.oracle.com/cd/E19957-01/800-7895/800-7895.pdf https://docs.oracle.com/cd/E19957-01/800-7895/800-7895.pdf
[2] http://ftp.demec.ufpr.br/CFD/bibliografia/Higham_2002_Accuracy%20and%20Stability%20of%20Numerical%20Algorithms.pdf http://ftp.demec.ufpr.br/CFD/bibliografia/Higham_2002_Accura...
- an1sotropy 4y agoI like and assign the Goldberg paper. I haven't spent much time with the Higham book; thank you for for full text link. In my class, FP computation is something I try to teach the students to be mindful of, but it is hardly the focus of the class (about certain kinds of data visualization). FP computation arises in lots of different places in many different functions, often in the context of a larger data processing pipeline that actually starts and ends with 16-bit integers (e.g. medical imaging data). So I'm not sure how I'd thoroughly exercise the FP-related code in the way that you describe. Hence my current use of something I can easily control at the outset of the whole pipeline (the direction of rounding). Do you have any ideas on injecting randomized rounding mode changes prior to FP ops in the assembly, or something functionally equivalent for characterizing C code (ideally without code changes)? I just found [1] which seems extremely related, but I'll have to look into whether the code still works. [1] http://www.iboview.org/random_rounding/ http://www.iboview.org/random_rounding/
- an1sotropy 4y agoAt the risk of just talking to myself, I'll note that a google scholar search on the [1] above led me to this phd [2] which in turn led me to two newer tools, Verrou [3] and Verificarlo [4] which involve Valgrind and Docker, respectively, though I'd have to understand what exactly is being contained by Docker for Verrou. But it makes me appreciate more the minimalist approach of Knizia et al. in [1], which does involve recompilation of modified assembly, but that's something I'm doing multiple times with student code already. [2] https://tel.archives-ouvertes.fr/tel-03110553/document https://tel.archives-ouvertes.fr/tel-03110553/document [3] https://github.com/edf-hpc/verrou https://github.com/edf-hpc/verrou [4] https://github.com/verificarlo/verificarlo https://github.com/verificarlo/verificarlo