title: Objective-C Float / Double precision
body: <p>I was messing around with storing <code>float</code>s and <code>double</code>s using <code>NSUserDefaults</code> for use in an iPhone application, and I came across some inconsistencies in how the precision works with them, and how I understood it works.</p>
  
  <p>This works exactly as I figured:</p>
  
  <pre><code>{
      NSString *key = @"OneLastKey";
      [PPrefs setFloat:235.1f forKey:key];
      GHAssertFalse([PPrefs getFloatForKey:key] == 235.1, @"");
      [PPrefs removeObjectForKey:key];
  }
  </code></pre>
  
  <p>However, this one doesn't:</p>
  
  <pre><code>{
      NSString *key = @"SomeDoubleKey";
      [PPrefs setDouble:234.32 forKey:key];
      GHAssertEquals([PPrefs getDoubleForKey:key], 234.32, @"");
      [PPrefs removeObjectForKey:key];
  }
  </code></pre>
  
  <p>This is the output GHUnit gives me:</p>
  
  <pre><code>'234.320007324' should be equal to '234.32'. 
  </code></pre>
  
  <p>But, if I first cast the double to a <code>float</code>, and then to a <code>double</code> it works without fail:</p>
  
  <pre><code>{
      NSString *key = @"SomeDoubleKey";
      [PPrefs setDouble:234.32 forKey:key];
      GHAssertEquals([PPrefs getDoubleForKey:key], (double)(float)234.32, @"");
      [PPrefs removeObjectForKey:key];
  }
  </code></pre>
  
  <p>I was under the assumption that numbers entered without an 'f' at the end were already considered <code>double</code>s. Is this incorrect? If so, why does casting to a <code>float</code> and then <code>double</code> work correctly?</p>