POV-Ray : Newsgroups : povray.unofficial.patches : Noisy thoughts : Re: Noisy thoughts Server Time
2 Sep 2024 04:15:50 EDT (-0400)
  Re: Noisy thoughts  
From: Tom Melly
Date: 29 Sep 2000 07:25:17
Message: <39d47c1d@news.povray.org>

news:39D46C9D.907A461A@enst.fr...
>
> Now I've got an interresting puzzle: knowing that "x_ix" and "x_jx" are
> both doubles, why is this:
> x_jx = 1 - x_ix;
> faster than this:
> x_jx = 1.0 - x_ix;
> ??
>

Can I guess? (I know practically nothing about C, and absolutely nothing
about it's internals). Assuming that there is nothing different about the
output of the calculation, could it be that, when x_ix is an integer value,
the first example will perform an integer calculation, whereas the second
example will always perform a floating point calculation?

My second guess would be that with the first example the compiler "knows"
that the result will have no more decimal places than are held by x_ix,
since 1 is an unequiviqual integer. With the second example, it does not
view 1.0 as an integer and therefore makes no assumption about the degree of
precision required in the answer. Am I close? Not even warm? Freezing cold?
An idiot?

Third guess (and this would imply some idiocy on the part of the compiler).
When it sees 1.0, it realises that it is an integer and first translates it
to 1 and then translates it back to a float for the purpose of the
calculation. With the first example, it is able to skip the first part of
this process.

BTW Sorry for the anthromorphisism.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.