I work much better with numbers. Can you give me an example of what you do and what you see precisely? Also, it would be good to test both ways: tech first then building first. If happiness is broken in exactly the same way then there's no need to post those results. If it is broken in a different way, post the tests you run.
For example: Biology gives +1

to Granary.
Tech then building: city screen shows +2

(bad)
Building then tech: city screen shows +1

(good)
Are the x

> y

next to the food bar correct? What about its hover text? What are the city gauges?
As for that calculation you posted, it needs to add the old negative value to the bad health (a positive value) to remove it, as it's doing, whereas below it subtracts the new negative value from the bad health to add it. When changing here, first remove old then add new.