<p><code>celsius = (5.0/9.0) * (fahr-32.0);</code></p>

<p>Is it just a development choice that the C developers decided upon or is there a reason to this? I believe a float is smaller than a double, so it might be to prevent overflows caused by not knowing what decimal format to use. Is that the reason, or am I overlooking something?</p>

[{'answer_id': 38207, 'author': 'Vaibhav', 'author_id': 380, 'author_profile': 'https://Stackoverflow.com/users/380', 'pm_score': 3, 'selected': True, 'text': '<p>I think the reason is to ensure that any result can be encompassed. so the natural choice is double as it is the largest data type.</p>\n'}, {'answer_id': 38208, 'author': 'dmckee --- ex-moderator kitten', 'author_id': 2509, 'author_profile': 'https://Stackoverflow.com/users/2509', 'pm_score': 1, 'selected': False, 'text': '<p>Floating point constants should have the available highest precision. The result can be assigned to a float without undue trouble.</p>\n'}, {'answer_id': 38229, 'author': 'Shog9', 'author_id': 811, 'author_profile': 'https://Stackoverflow.com/users/811', 'pm_score': 5, 'selected': False, 'text': "<pre><code>celsius = (5.0/9.0) * (fahr-32.0);\n</code></pre>\n\n<p>In this expression, <code>5.0</code>, <code>9.0</code>, and <code>32.0</code> are <code>double</code>s. That's the default type for a floating-point constant - if you wanted them to be <code>float</code>s, then you would use the <code>F</code> suffix:</p>\n\n<pre><code>celsius = (5.0F/9.0F) * (fahr-32.0F);\n</code></pre>\n\n<p>Note that if <code>fahr</code> was a <code>double</code>, then the result of this last expression would <em>still</em> be a <code>double</code>: as Vaibhav noted, types are promoted in such a way as to avoid potentially losing precision.</p>\n"}, {'answer_id': 38234, 'author': 'hoyhoy', 'author_id': 3499, 'author_profile': 'https://Stackoverflow.com/users/3499', 'pm_score': 2, 'selected': False, 'text': '<p>The reason that the expression is cast to double-precision is because the literals specified are double-precision values by default.  If you specify the literals used in the equation as floats, the expression will return a float.  Consider the following code (Mac OS X using gcc 4.01). </p>\n\n<pre><code>#include &lt;stdio.h&gt;\nint main() {\n  float celsius;\n  float fahr = 212;\n  printf("sizeof(celsius) ---------------------&gt; %d\\n", sizeof(celsius));\n  printf("sizeof(fahr) ------------------------&gt; %d\\n", sizeof(fahr));\n  printf("sizeof(double) ----------------------&gt; %d\\n", sizeof(double));\n  celsius = (5.0f/9.0f) * (fahr-32.0f);\n  printf("sizeof((5.0f/9.0f) * (fahr-32.0f)) --&gt; %d\\n", sizeof((5.0f/9.0f) * (fahr-32.0f)));\n  printf("sizeof((5.0/9.0) * (fahr-32.0)) -----&gt; %d\\n", sizeof((5.0/9.0) * (fahr-32.0)));\n  printf("celsius -----------------------------&gt; %f\\n", celsius);\n}\n</code></pre>\n\n<p>Output is:</p>\n\n<pre><code>sizeof(celsius) ---------------------&gt; 4\nsizeof(fahr) ------------------------&gt; 4\nsizeof(double) ----------------------&gt; 8\nsizeof((5.0f/9.0f) * (fahr-32.0f)) --&gt; 4\nsizeof((5.0/9.0) * (fahr-32.0)) -----&gt; 8\ncelsius -----------------------------&gt; 100.000008\n</code></pre>\n'}, {'answer_id': 1307035, 'author': 'amaterasu', 'author_id': 158234, 'author_profile': 'https://Stackoverflow.com/users/158234', 'pm_score': 1, 'selected': False, 'text': "<p>Back in the day of K&amp;Rv1, it was encouraged to use float/double interchangeably being as all expressions with floating-point types were always evaluated using `double' representation, a problem in cases where efficency is paramount. A floating-point constant without an f, F, l, or L suffixed is of type double. And, if the letter f or F is the suffix, the constant is of type float. And if suffixed by the letter l or L, it is of type long double.</p>\n"}]
['https://Stackoverflow.com/questions/38198', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/572/']