Floating point division vs floating point multiplication

后端 未结 7 1761
醉话见心
醉话见心 2020-11-22 11:37

Is there any (non-microoptimization) performance gain by coding

float f1 = 200f / 2

in comparision to

float f2 = 200f * 0.5         


        
7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 12:11

    Newton rhapson solves integer division in O(M(n)) complexity via linear algebra apploximation. Faster than The otherwise O(n*n) complexity.

    In code The method contains 10mults 9adds 2bitwiseshifts.

    This explains why a division is roughly 12x as many cpu ticks as a multiplication.

提交回复
热议问题