Thanks much for the equation. But I'm finding a difficulty with negative nature stats.
Example of my situations. Lvl 50 Fennekin, Gentle, 115, 65, 45, 80, 88, 76. Calculator gives me 31, 31, 13, 27, 31, 23. My spreadsheet gives me 31, 31, 11, 27, 31, 23. Gentle is Lower Defense, higher Special Defense. The negative stat is the only one that seems to be off. Each check is only by 2, but it's still off somehow.
Good news is though, it does well with positive stats and still gives me accurate numbers for the great stats (and if the stat is a perfect one even on a negative nature)