# Temperature Conversion

By Susam Pal on 05 Jan 2014

## Approximation Problem

Everytime I travel to the US, one thing that troubles me a little is having to convert temperature from the Celsius scale to the Fahrenheit scale and vice versa. The exact conversion formulas are: \begin{align*} f & = \frac{9c}{5} + 32, \\ c & = \frac{5(f - 32)}{9} \end{align*} where $$f$$ represents the temperature value in Fahrenheit and $$c$$ represents the temperature value in Celsius.

While the formulas above are accurate, they are not very convenient to mentally figure what I need to set a room thermostat in Fahrenheit scale to if I want to keep the room at, say, 25 °C. For this particular case, I have memorized that 25 °C is 77 °F. This combined with the fact that every 5 °C interval corresponds to an interval of 9 °F, it is easy to mentally compute that 20 °C is 68 °F or 22.5 °C is 72.5 °F. It would still be nice to find an easy way to mentally convert any arbitrary temperature in one scale to the other scale.

In my last trip to the US, I decided to devise a few approximation methods to convert temperature from the Fahrenheit scale to the Celsius scale and vice versa. I arrived at two methods: one to convert temperature value in Fahrenheit to Celsius and another to convert from Fahrenheit to Celsius. Both these methods are based on the exact conversion formulas but they sacrifice accuracy a little bit in favour of simplifying the computations, so that they can be performed mentally.

## Crude Approximation Methods

Before we dive into the refined approximation methods I have arrived at, let us first see a very popular method that obtains a crude approximation of the result of temperature conversion from °C to °F and vice versa pretty quickly.

To go from °C to °F, we perform the following two steps:

1. Double the value in Celsius.
2. Add 30 to the previous result.

To go from °F to °C, we perform the inverse:

1. Subtract 30 from the value in Fahrenheit.
2. Halve the result.

We arrive at the above methods by approximating 9/5 and 32 in the exact conversion formulas with 2 an 30, respectively. These methods can be performed mentally quite fast but this speed of mental calculation comes at the cost of accuracy. That's why I call them crude approximation methods.

The first method converts 10 °C exactly to 50 °F without any error. But then it introduces an error of 1 °F for every 5 °C interval. For example, the error is 3 °F for 25 °C and 18 °F for 100 °C.

Similarly, the second method converts 50 °F exactly to 10 °C without any error. But it introduces an error of 0.5 °C for every 9 °F interval. For example, the error is 1.5 °C for 77 °C and 9 °C for 212 °F.

### Examples

Let us do a few examples to see how well the crude approximation methods work. Let us say, we want to convert 24 °C to °F.

1. Double 24. We get 48.
2. Add 30 to it. We get 78.

The exact value for 24 °C is 75.2 °F. This approximation method overestimated the actual temperature in Fahrenheit by 2.8 °F.

Let us now convert 75 °F to °C.

1. Subtract 30. We get 45.
2. Divide by 2. We get 22.5.

The exact value for 75 °F is 23.89 °C. This approximation method underestimated the actual temperature in Celsius by 1.39 °C.

Can we do better?

## Refined Approximation Methods

This section presents the refined approximation methods that I have arrived at. They can be performed mentally. They are a little slower than the crude approximation methods but they are more accurate.

To keep the methods convenient enough to perform mentally, we work with integers only. We always start with an integer value in Celsius or Fahrenheit. The result of conversion is also an integer. If a fraction arises in an intermediate step, we discard the fractional part. For example, if a step requires us to calculate one-tenth of a number, say, 25, we consider the result to be 2. Similarly, if a step requires us to halve the number 25, we consider the result to be 12. This is also known as floor division or integer division.

To go from °C to °F, here is my quick three-step approximation method:

1. Subtract one-tenth of the value in Celsius from itself.
2. Double the previous result.
3. Add 31 to the previous result.

The approximation error due to this method does not exceed 1 °F in magnitude. In terms of Celsius, the approximation error does not exceed 0.56 °C. I believe this is pretty good if we are talking about setting the thermostat temperature.

To go from °F to °C, we roughly inverse the above steps:

1. Subtract 31 from the value in Fahrenheit.
2. Halve the result.
3. Add one-tenth of the previous result to itself.

In fact, for integer temperature values between 32 °F (0 °C) and 86 °F (30 °C), the approximation error due to this method does not exceed 1.12 °C. Further, for integer temperature values between −148 °F (−100 °C) and 212 °F (100 °C), the approximation error does not exceed 1.89 °C. This is pretty good if we are talking about the weather.

### Examples

Let us do a few examples to see how well the three-step methods above work. Let us say, we want to convert 24 °C to °F.

1. Subtract one-tenth of 24 from itself, i.e., subtract 2 from 24. We get 22.
2. Double 22. We get 44.
3. Add 31 to 44. We get 75.

The exact value for 22 °C is 75.2 °F. The approximation method has underestimated the actual temperature in Fahrenheit by only 0.2 °F.

Let us now try to convert 75 °F to °C.

1. Subtract 31 from 75. We get 44.
2. Halve 44. We get 22.
3. Add one-tenth of 22 to itself, i.e., add 2 to 22. We get 24.

The exact value for 75 °F is 23.89 °C, so this approximation method overestimated the actual temperature in Celsius by 0.11 °C only.

If you were looking only for quick methods to convert temperature values in Fahrenheit to Celsius and vice versa, this is all you need to know. You may skip the remaining post unless you want to know why these methods work.

### Analysis

In this section, we will see why the refined approximation methods work so well.

#### Celsius to Fahrenheit Conversion

The method to convert temperature value from Celsius to Fahrenheit is equivalent to $\overset{\approx}{f} = 2 \left(c - \left\lfloor \frac{c}{10} \right\rfloor \right) + 31$ where $$c$$ is the temperature value in Celsius and $$\overset{\approx}{f}$$ is the approximate temperature value in Fahrenheit.

Here is a brief justification for this:

1. Subtracting one-tenth (floor division by 10) of $$c$$ from itself gives us $$c - \left\lfloor \frac{c}{10} \right\rfloor.$$
2. Doubling the previous result gives us $$2 \left(c - \left\lfloor \frac{c}{10} \right\rfloor \right).$$
3. Adding $$31$$ to the previous result gives us $$2 \left(c - \left\lfloor \frac{c}{10} \right\rfloor \right) + 31.$$

Now let us see how we arrive at the above approximate conversion formula. It's not too different from the exact conversion formula. The exact formula to convert temperature from Celsius to Fahrenheit is $f = \frac{9c}{5} + 32.$

This can be rewritten as $f = 2 \left(c - \frac{c}{10} \right) + 32.$

We don't want to deal with fractions, so we decide to approximate $$\frac{c}{10}$$ in the above formula with $$\left\lfloor \frac{c}{10} \right\rfloor$$ and get $\overset{\sim}{f} = 2 \left(c - \left\lfloor \frac{c}{10} \right\rfloor \right) + 32.$ where $$\overset{\sim}{f}$$ is an approximation of the value in Fahrenheit. The floor division has the effect of potentially overestimating the final result by a value that is less than $$2.$$ This is the approximation error.

If we define the approximation error as $$\overset{\sim}{f} - f,$$ then the approximation error lies in the half-open interval $$[0, 2).$$ To ensure that the magnitude of the error never exceeds $$1,$$ i.e., to make the approximation error lie in the half-open interval $$[-1, 1),$$ we subtract $$1$$ from the above formula and get $\overset{\approx}{f} = 2 \left(c - \left\lfloor \frac{c}{10} \right\rfloor \right) + 31.$ This is the formula that the three-step method to convert temperature from Celsius to Fahrenheit is equivalent to.

#### Fahrenheit to Celsius Conversion

The inverse method to convert temperature value from Fahrenheit to Celsius amounts to this formula: $\overset{\approx}{c} = \left\lfloor \frac{f - 31}{2} \right\rfloor + \left\lfloor \frac{f - 31}{20} \right\rfloor$ where $$f$$ is the temperature value in Fahrenheit and $$\overset{\approx}{c}$$ is the approximate temperature value in Celsius.

Here is a brief justification for this:

1. Subtracting $$31$$ from $$f$$ gives us $$f - 31.$$
2. Halving (floor division by $$2$$) the previous result gives us $$\left\lfloor \frac{f - 31}{2} \right\rfloor.$$
3. Adding one-tenth (floor division by $$10$$) of the previous result to itself gives us $$\left\lfloor \frac{f - 31}{2} \right\rfloor + \left\lfloor \frac{1}{10} \left\lfloor \frac{f - 31}{2} \right\rfloor \right\rfloor = \left\lfloor \frac{f - 31}{2} \right\rfloor + \left\lfloor \frac{f - 31}{20} \right\rfloor.$$

This is roughly an inverse of all the steps for converting a temperature value from Celsius to Fahrenheit. Let us see if this is close to the exact conversion formula $c = \frac{5(f - 32)}{9}.$

It turns out that it is in fact close to the exact conversion formula as follows: \begin{align*} c & = \frac{5(f - 32)}{9} \\ & = 0.5556 (f - 32) \\ & \approx 0.55 (f - 31) \\ & = \frac{11 (f - 31)}{20} \\ & = \frac{f - 31}{2} + \frac{f - 31}{20} \\ & \approx \left\lfloor \frac{f - 31}{2} \right\rfloor + \left\lfloor \frac{f - 31}{20} \right\rfloor = \overset{\approx}{c} \end{align*}

Like we discussed earlier, the magnitude of the approximation error does not exceed 1.89 °C for integer values between −148 °F and 212 °F. The error here is a little bit more than the previous approximation method to convert temperature in Celsius to Fahrenheit but it is still small enough to give us a reasonably good estimate of what a temperature value in Fahrenheit would look like in Celsius when we are talking about the weather.