Average function without overflow exception

后端 未结 18 1721
一生所求
一生所求 2021-02-12 14:58

.NET Framework 3.5.
I\'m trying to calculate the average of some pretty large numbers.
For instance:

using System;
using System.Linq;

class Program
{
           


        
18条回答
  •  抹茶落季
    2021-02-12 15:32

    For two positive numbers (or two negative numbers) , I found a very elegant solution from here.

    where an average computation of (a+b)/2 can be replaced with a+((b-a)/2.

提交回复
热议问题