0

For a vector (set of numbers) whose multiplication or division would exceed the minimum or maximum value of type double and/or decimal, how could the geometric mean and harmonic mean be calculated?

Any existing implementation I have found did not make this consideration (i.e. they could calculate a small set, but not a large set).

Aalawlx
  • 593
  • 5
  • 25
  • If perfomance is important, you can look for ideas in this question: https://stackoverflow.com/q/19980319/5311735. It's C++, but problem is the same, and double behaves the same in C++ and C#. – Evk Mar 11 '18 at 07:26
  • @Evk thanks for that link. It is very helpful. I will try to port that method to c#. – Aalawlx Mar 11 '18 at 11:59

1 Answers1

1

It's possible to multiply numbers of any size (e.g. bigger than any MaxValue) by representing them as strings, and writing a method to calculate the result.

If you did "long multiplication" in school, that is the algorithm to follow, just calculating one digit at a time and working your way along from least significant digit to most significant.

Similarly, you can do division of these string based numbers by writing a method to do "long division". You can build a method for geometric mean based on those. I don't know about "harmonic mean"s... but I'm hoping that would also be solvable at that point.

Hope this helps.

Richardissimo
  • 5,596
  • 2
  • 18
  • 36