I understand what you mean by rounding error, thanks for the additional info. It is not the case with this bug report.
I've done more digging and have finally found a formula that explains the bug so I can at least in the meantime apply a workaround in my mod until it's (hopefully) fixed.
TL;DR the final use when it removes an item, the cook bonus that reduces the amount used of an item applies, when we should actually be using the entire item up, hence the lost calories. It is not a small number. This is per item use in a recipe, so if we were to minmax loses with the bug, we can lose at least 710.1 calories in the example below in a single rabbit meat stew.
Calculating nutrition given a cook skill:
example with default rabbitmeat spawned in debug mode
$foodHunger = 30
$foodCalories = 969
$recipeHungerCost = 15
$cookPerkLevel = 10
$cookReductionBonus = 1 - (0.03 * $cookPerkLevel)
$cookNutritionIncrease = 1 + ($cookPerkLevel / 15)
$reducedRecipeCost = $recipeHungerCost * $cookReductionBonus
$percentageOfFoodToUse = MIN($reducedRecipeCost / $foodHunger, 1)
$CaloriesInStew = $cookNutritionIncrease * $foodCalories * $percentageOfFoodToUse = 565.25
$foodHunger = $foodHunger * (1 - $percentageOfFoodToUse) = 19.5
$foodCalories = $foodCalories * $percentageOfFoodToUse = 629.85
These numbers checkout in-game nutrition values.
Second use of the item:
$CaloriesInStew += $cookNutritionIncrease * $foodCalories * $percentageOfFoodToUse = 1130.5
$foodHunger = $foodHunger * (1 - $percentageOfFoodToUse) = 9
$foodCalories = $foodCalories * $percentageOfFoodToUse = 290.7
second use also exactly checks out with in-game nutrition values.
Now this is where things get funky on the final, third use now that $foodHunger is less than $recipeHungerCost.
The $percentageOfFoodToUse never gets set to 1 in zomboid if the cook skill is higher than 0. For some reason, after wracking my brains somewhat while playing with this formula, $recipeHungerCost gets set to the same value as $foodHunger when it's the final use of a food item, but before the reduced recipe cost calculation, instead of setting $reducedRecipeCost to the value of $foodHunger. This means the reduction-bonus applies, and we lose calories since the item is tossed after this final use. To demonstrate in a formula:
$recipeHungerCost = $foodHunger = 9
$reducedRecipeCost = $recipeHungerCost * $cookReductionBonus = 6.3
$percentageOfFoodToUse = MIN($reducedRecipeCost / $foodHunger, 1) = 0.7
In this example, we only get to use 70% of the food item instead of 100%, then throw the remaining rabbitmeat away. This equation above accurately calculates what we see ingame (with a final rounding error of 0.01 for proteins,carbs and lipids vs what is displayed ingame, but calories is high enough not to have rounding errors)
Final values:
Stew with 3x rabbitmeat uses has calories 1469.65 as it stands in zomboid right now.
If this bug is fixed, it should be atleast 1615 calories @cook level 10. That's a 9% difference, or a 118.35 calorie difference for a single recipe ingredient in a stew which takes up to 6 ingredients. With rabbitmeat alone we could see losses up to 710.1 calories for a single stew in the right circumstances. This is a significant potential loss of nutrition during a long playthough and we're only talking about a single meal out of the hundreds if not thousands people cook.
Thank you if you managed to read this far. I hope I wrote clearly enough and that perhaps a dev in the future might have a look into this. I can upload a spreadsheet file that I used to figure all this out, it might be a little easier to follow than the wall of text above.