Floating point division vs floating point multiplication

后端 未结 7 1612
醉话见心
醉话见心 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:13

    The answer depends on the platform for which you are programming.

    For example, doing lots of multiplication on an array on x86 should be much faster then doing division, because the compiler should create the assembler code which uses SIMD instructions. Since there are no division in the SIMD instructions, then you would see great improvements using multiplication then division.

    0 讨论(0)
提交回复
热议问题