On Fri, 22 May 2026, 02:20 Andrew Pinski via Gcc, <[email protected]> wrote:
> On Thu, May 21, 2026 at 6:04 AM Undisclosed via Gcc <[email protected]> > wrote: > > > > Hi, I am using gcc 14.2 on windows (mingw64). > > I always gave for granted that any compiler would automatically turn > constant divisions into multiplications. Thus, I never cared of writing i.e > > float x = a * 0.1f > > but I always wrote > > float x = a / 10.f > > trusting the compiler. > > Now I decided to inspect the asm, to be 100% sure, cos I was detecting > abnormal cpu consumption in some time-critical code, and I had a very bad > surprise !!! > > > > Here is how: > > > > float Func(float x) > > { > > return x / 10.f; > > } > > > > gets resolved: > > > > divss .LC12(%rip), %xmm0 !!! > > > > This with: > > > > -m64 -march=x86-64-v3 -O3 > > > > Does it make any sense ? Why doesn't it convert the division by 10 to a > multiplication by 0.1 ?? Has one to enable some specific option for that ? > > 0.1 is not exactly representable in floating point types. This is why > it is not converted by default. > Consider: (0.1f / 10.0f) == (0.1f * 0.1f) This is false, they are not equal. >
