di is the distance from the image to the mirror or lens
For a mirror, it is positive if the image appears in front of the mirror. It is negative if the image appears behind.
For a lens, it is positive if the image appears on the opposite side of the lens as the light source. It is negative if the image appears on the same side of the lens as the light source.
do is the distance from the object to the mirror or the lens (always positive). The only case, when it is negative, is the case, when you don't have a real object, but you do have an imaginary object - a converging set of rays from another optical system.
an easy way to remember the formula is to memorize "if I Do I Die", which stands for 1/f = 1/d_0 + 1/d_i
Magnification
M is the magnification.
If it is positive the image is upright
If it is negative the image is inverted
hi is the image height.
ho is the object height.
di is the distance from the image to the mirror or lens (also often v)
For a mirror, it is positive if the image appears in front of the mirror. It is negative if the image appears behind.
For a lens, it is positive if the image appears on the opposite side of the lens as the light source. It is negative if the image appears on the same side of the lens as the light source.
do is the distance from the object to the mirror or lens (also often u)