“Approximate” greatest common divisor

前端 未结 8 1112
清歌不尽
清歌不尽 2020-12-13 17:11

Suppose you have a list of floating point numbers that are approximately multiples of a common quantity, for example

2.468, 3.700, 6.1699

w

8条回答
  •  庸人自扰
    2020-12-13 18:01

    The solution which I've seen and used myself is to choose some constant, say 1000, multiply all numbers by this constant, round them to integers, find the GCD of these integers using the standard algorithm and then divide the result by the said constant (1000). The larger the constant, the higher the precision.

提交回复
热议问题