Timeline for Which is preferred: subclass double or create extension methods to test (relative) equality due to floating point differences?
Current License: CC BY-SA 4.0
19 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 26, 2020 at 6:00 | history | tweeted | twitter.com/StackSoftEng/status/1320606097867182080 | ||
Oct 23, 2020 at 4:04 | vote | accept | Brie | ||
Oct 22, 2020 at 20:18 | comment | added | supercat |
@rwong: From what I understand, a related difference between FORTRAN and C is that in FORTRAN, if one has two array references a() and b() , a compiler need not accommodate the possibility that a(i) might alias b(i+ofs) for any non-zero value of ofs , but would be required to accommodate the possibility that a() and b() might be the same array, and thus a(i) and b(i) might identify the same storage.
|
|
Oct 22, 2020 at 17:55 | comment | added | rwong | The performance secret of Fortran is that it restricts what things may alias (overlap). Without knowing that two arrays do not have partial overlap in memory, many theoretically possible optimizations performed by a C optimizer can produce different results depending on whether partial overlap occurs in two arrays, if those two arrays are not used in a strictly read-only fashion. It is not an insurmountable problem; some C optimizers can issue explicit array range overlap check instructions, and branch to optimizing/non-optimizing routines that produce result consistent with the C specificatio | |
Oct 21, 2020 at 13:26 | comment | added | Nobody | What kind of numerical calculations are you doing that equality tests are important? Generally algorithms in numerical analysis rely more on tests for inequality. E.g., you deem an algorithm converged when the error is less than some tolerance. About the only time you test for (approximate) equality in practice is when validating results against a known standard, and there it's easy enough to just use an approximate comparison subroutine, instead of pretending that you're really testing for "equality". | |
Oct 21, 2020 at 9:59 | comment | added | leftaroundabout | @OrangeDog BLAS deals with an extremely simple, extremely homogeneous sort of problem, which thus lends itself ideally for Fortran. For linear algebra, the right thing to do is generally to call that library, regardless from what language you use yourself. (Also: neither C nor Fortran is best in BLAS – Cuda is.) | |
Oct 21, 2020 at 9:26 | comment | added | OrangeDog | @leftaroundabout the Fortran implementation of BLAS outperforms the C, for example (due to additional language restrictions allowing more advanced optimisations). The garbage collection has nothing to do with it, it's the JIT not making use of e.g. vectorisation. Also, if you are using floating point, you can disable denorm and NaN checks if you know they won't be an issue. | |
Oct 21, 2020 at 9:02 | comment | added | leftaroundabout | @OrangeDog Fortran doesn't buy you anything over C++ or Rust unless perhaps if you're using arrays that are parallelized across a supercomputer cluster. And whilst garbage-collected languages like C#, Java and Haskell are indeed generally somewhat slower, it's not a huge difference (whereas dynamic languages or decimal arithmetic are much slower than floating-point in any of those languages). So, it can be a perfectly valid decision to use C# here. | |
Oct 21, 2020 at 8:18 | comment | added | OrangeDog | Note that "blazingly fast" software is unless if it gives completely wrong answers. I also question whether C# is an appropriate choice given your stated requirements. For maximal performance of correct maths, Fortran usually wins. | |
Oct 21, 2020 at 7:42 | comment | added | Damien_The_Unbeliever |
How would you subclass double when it's a value type and, by definition, not eligible to be a base class?
|
|
Oct 21, 2020 at 6:02 | history | became hot network question | |||
Oct 21, 2020 at 5:38 | answer | added | Doc Brown | timeline score: 47 | |
Oct 21, 2020 at 5:04 | review | Close votes | |||
Oct 26, 2020 at 3:03 | |||||
Oct 20, 2020 at 22:18 | answer | added | Brie | timeline score: 8 | |
Oct 20, 2020 at 21:58 | history | edited | Brie | CC BY-SA 4.0 |
Clarification
|
Oct 20, 2020 at 21:30 | answer | added | Caleth | timeline score: 26 | |
Oct 20, 2020 at 21:30 | answer | added | gnasher729 | timeline score: 13 | |
Oct 20, 2020 at 21:11 | review | First posts | |||
Nov 3, 2020 at 21:12 | |||||
Oct 20, 2020 at 21:07 | history | asked | Brie | CC BY-SA 4.0 |