What is the fastest way to get the value of π?

后端 未结 23 1796
自闭症患者
自闭症患者 2020-11-28 00:33

I\'m looking for the fastest way to obtain the value of π, as a personal challenge. More specifically, I\'m using ways that don\'t involve using #define constan

23条回答
  •  忘掉有多难
    2020-11-28 00:52

    Back in the old days, with small word sizes and slow or non-existent floating-point operations, we used to do stuff like this:

    /* Return approximation of n * PI; n is integer */
    #define pi_times(n) (((n) * 22) / 7)
    

    For applications that don't require a lot of precision (video games, for example), this is very fast and is accurate enough.

提交回复
热议问题