I recently came accross this code:
Mat3D R_z(double RotAngle)
{
const double S = sin (RotAngle);
const double C = cos (RotAngle);
Mat3D U;
U.m_Mat[0][0] = +C; U.m_Mat[0][1] = +S; U.m_Mat[0][2] = 0.0;
U.m_Mat[1][0] = -S; U.m_Mat[1][1] = +C; U.m_Mat[1][2] = 0.0;
U.m_Mat[2][0] = 0.0; U.m_Mat[2][1] = 0.0; U.m_Mat[2][2] = 1.0;
return U;
}
My question: why should the keyword const
be used in this case?
The variables C and S are IMHO just a bit of syntactic sugar, to make the rest of the code somewhat easier to read.