The question has an underlying issue in naming the things it is converting. The formulas given in the question do NOT convert "Hertz to cents" but rather convert interval ratios to cents (and the reverse).
The problem can be seen in a couple different ways:
- The "Hertz numbers" used in the question are not simply numbers, but ratios, like 3/2 = 1.5 being a perfect fifth, 9/8 = 1.125 = a whole tone, etc. These are not Hertz per se, but ratios of frequencies (perhaps measured in Hertz, but one could measure them in any unit). In other words, they are dimensionless ratios, not "Hertz." [See NOTE below] One cannot simply add and subtract ratios to find the interval between those ratios. Instead one multiplies or divides them. For example, to "add" a perfect fifth and a perfect fourth, one multiplies
(3/2) * (4/3) = 12/6 = 2/1 (an octave). Adding the fractions
3/2+4/3 = 17/6 wouldn't give you anything having to do with the musical interval. Similarly, the subtractions you perform with the "Hertz numbers" (e.g., ABS(1.117-1.125)) have no musical interval meaning, nor do they have a direct relationship to frequencies measured in Hertz or otherwise.
- Logarithms have basic properties. When you perform a logarithm on two numbers you multiply, it is equivalent to adding the logarithms of the two individual numbers, i.e., LOG(A*B)=LOG(A)+LOG(B). Similarly, when you take a logarithm of two numbers you divide, it is equivalent to subtracting the logarithms, i.e., LOG(A/B)=LOG(A)-LOG(B). Thus, when you apply your "cents" function and take the logarithms, you can add or subtract the resulting amount of cents to find a larger or smaller musical interval. To take my previous example, 1200*LOG(3/2,2)=701.955 cents (as you note). For a perfect fourth, 1200*LOG(4/3,2)=498.045 cents. Adding these two values gives 1200 cents, which using your other formula 2^(1200/1200) gives 2 or the ratio 2/1, i.e., an octave, as we expect.
So, to fix your examples, note that it is meaningless to add or subtract the ratios A and B you call "Hertz" (but again, which are actually dimensionless ratios). If you wanted to find the difference between the size of intervals A and B, you would divide the ratios.
Frequency Ratio (A) = 1.117
Frequency Ratio (B) = 1.125
Difference in Size = B/A = 1.007162 (Note this number is NOT measured in Hertz, it is also a frequency ratio.)
Frequency Ratio (C) = 1.7904
Frequency Ratio (D) = 1.8
Difference in Size = D/C = 1.00536
Now, if you convert these results to cents:
For B/A = 1200*LOG(1.007162,2) = 12.35 cents
For D/C = 1200*LOG(1.00536,2) = 9.258 cents
These calculations now agree with your results of subtracting the intervals as measured in cents.
NOTE: The ratios are potentially related to Hertz. For example, a 3/2 ratio is a perfect fifth. Any two frequencies in that ratio would create a perfect fifth, e.g., 300 Hertz to 200 Hertz = 300/200 = 3/2. Or 660 Hertz to 440 Hertz = 660/440 = 3/2. However, the 3/2 ratio is not measured in Hertz, as the units cancel out when you divide the two frequencies. Also, note that there is no direct mathematical way to convert a subtracted difference in Hertz to a difference in cents, as the same musical interval in cents will have difference sizes in its frequency difference in Hertz, depending on its location in the scale. (For details on the latter, see other answers here.)