2

Now I am working on implementing complex numbers for ANSI C, but some mathematical formulas need improvement because floating point numbers are prone to loss of precision. In my implementation, I prefer double for represent of real numbers. I'm currently interested in the high-precision formula for division.

I looked at two possible approaches:

  1. Microsoft C# implementation
  2. GCC implementation

What other approaches exist?

Which implementation is the best?

How to choose an implementation for my project?

Thomas Jager
  • 4,836
  • 2
  • 16
  • 30
PavelDev
  • 579
  • 4
  • 12
  • 1
    What are you trying to do, exactly? The C# code you linked to is just a wrapper function for dividing two `Complex` values. The GCC code you linked to is the generic implementation for the operator `/=` on `complex` values. Nothing here does division in any special way. The GCC code uses the division underlying the types. The C# code is just a wrapper for the `/` operator. – Thomas Jager Apr 29 '20 at 14:59
  • also, you'd need to define "best": are you interested in maximum (worst case?) precision only, or is performance also a factor? Do you want to maximize precision for a certain range of values, or average precision over the whole double range? How do you measure the numerical error that you want to minimize? – Hulk Apr 29 '20 at 15:06
  • Your requirements are not clear. Why do you need "high precision"? For which algorithm? Maybe you can work around the precision loss using some known techniques (such as performing calculations on original values instead of accumulating error)? Or maybe you can even end up with fixed point calculations? – Eugene Sh. Apr 29 '20 at 15:28
  • @ThomasJager The Microsoft implementation begins at line 131 and it is called "Smith's formula". – PavelDev Apr 29 '20 at 15:28
  • 3
    You might look into Michael Baudin, Robert L. Smith "A Robust Complex Division in Scilab" [arxiv.org](https://arxiv.org/abs/1210.4539) which discusses the pros and cons of the individual algorithms in detail. They also introduce an algorithm that they say is better than Smith's (Smith's is **the** classic one from 1962 and also the algorithm Microsoft uses). – deamentiaemundi Apr 29 '20 at 15:43
  • cannot use ``? see https://ideone.com/ZRc04G – pmg Apr 29 '20 at 16:25

0 Answers0