[haiku-commits] Re: r40109 - haiku/trunk/src/add-ons/screen_savers/butterfly

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 04 Jan 2011 17:56:42 +0100

On 2011-01-04 at 17:24:12 [+0100], Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> 
wrote:
> leavengood@xxxxxxxxx wrote:
> > Fix coding violations, improve variable naming, remove strange float
> > constants
> > like 4.f.
> 
> They aren't strange, and just denote a float instead of a double. In
> functions that take float they make sense to use, and might even be
> needed in order to calm down some compiler warnings.

Moreover, please note that replacing e.g. 15.0f (or 15.f) by 15.0 forces 
the computation to double precision. So, unless that's desired, please 
leave the 15.0f or, preferrably, just use 15, which is int and gets 
automatically promoted to float when necessary.


On 2011-01-04 at 17:14:25 [+0100], leavengood@xxxxxxxxx wrote:
> -const float kOneSixth = 0.1666666666666666666f; // 1/2 * 1/3
> +const float kOneSixth = 0.5 * (1.0/3.0); // 1/2 * 1/3

I have serious trouble seeing the purpose of this computation (why not 
simply 1.f / 6?) or the comment for that matter.

Anyway, there's no point in defining the constant in the first place. 
Neither does it abstract some arbitrarily chosen value or one that is hard 
to compute/represent, nor does it improve readability or performance. So 
unless the constant falls into the first category after all (in which case 
it should be named appropriately), the four "*= kOneSixth" occurrences can 
simply be replaced by "/= 6".

CU, Ingo

Other related posts: