Changeset 52074 in webkit


Ignore:
Timestamp:
Dec 13, 2009 4:14:13 PM (14 years ago)
Author:
mitz@apple.com
Message:

Add a style guideline concerning floating point literals
https://bugs.webkit.org/show_bug.cgi?id=32497

Reviewed by Sam Weinig.

  • coding/coding-style.html:
Location:
trunk/WebKitSite
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitSite/ChangeLog

    r51932 r52074  
     12009-12-13  Dan Bernstein  <mitz@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Add a style guideline concerning floating point literals
     6        https://bugs.webkit.org/show_bug.cgi?id=32497
     7
     8        * coding/coding-style.html:
     9
    1102009-12-09  Marwan Al Jubeh  <marwan.aljubeh@gmail.com>
    211
  • trunk/WebKitSite/coding/coding-style.html

    r51929 r52074  
    422422</li>
    423423<li>In Objective-C, instance variables are initialized to zero automatically. Don't add explicit initializations to nil or NO in an init method.</li>
     424</ol>
     425
     426<h3>Floating point literals</h3>
     427<ol>
     428<li>Unless required in order to force floating point math, do not append
     429<code>.0</code>, <code>.f</code> and <code>.0f</code> to floating point
     430literals.
     431
     432<h4 class="right">Right:</h4>
     433<pre class="code">
     434const double duration = 60;
     435
     436void setDiameter(float diameter)
     437{
     438    radius = diameter / 2;
     439}
     440
     441setDiameter(10);
     442
     443const int framesPerSecond = 12;
     444double frameDuration = 1.0 / framesPerSecond;
     445</pre>
     446
     447<h4 class="wrong">Wrong:</h4>
     448<pre class="code">
     449const double duration = 60.0;
     450
     451void setDiameter(float diameter)
     452{
     453    radius = diameter / 2.f;
     454}
     455
     456setDiameter(10.f);
     457
     458const int framesPerSecond = 12;
     459double frameDuration = 1 / framesPerSecond; // integer division
     460</pre>
     461</li>
    424462</ol>
    425463
Note: See TracChangeset for help on using the changeset viewer.