[llvm-dev] different output with fast-math flag

sangeeta chowdhary via llvm-dev llvm-dev at lists.llvm.org
Tue Aug 21 11:11:41 PDT 2018


$ clang -v

clang version 7.0.0 (trunk 336308)

Target: x86_64-unknown-linux-gnu

Thread model: posix


$ cat fmath.c


#include<stdio.h>


int main() {

  double d = 1.0;

  double max = 1.79769e+308;

  d /= max;

  d *= max;

printf("d:%e:\n", d);

  return 0;

}


$ clang fmath.c

$ ./a.out

d:1.000000e+00:

$ clang  -ffast-math fmath.c

$ ./a.out

d:0.000000e+00:



On Tue, Aug 21, 2018 at 2:04 PM Tim Northover <t.p.northover at gmail.com>
wrote:

> Hi,
>
> On Tue, 21 Aug 2018 at 09:50, sangeeta chowdhary via llvm-dev
> <llvm-dev at lists.llvm.org> wrote:
> > I feel that its because d/max is really small number and fast-math does
> not care about small numbers and consider them to zero but this is so
> incorrect.
>
> Which version of Clang are you using? I see 1.0 in all cases I've
> tested, which is not terribly surprising. There isn't really much for
> fast-math to latch onto in the example, all the compiler might do is
> evaluate the constant result, and there's no reason to do it
> imprecisely.
>
> Cheers.
>
> Tim.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180821/1eaa0dcf/attachment.html>


More information about the llvm-dev mailing list