Feature request: add degToRad and radToDeg to phobos / tango

Spacen Jasset spacenjasset at yahoo.co.uk
Wed Apr 2 06:55:44 PDT 2008


Hello,

I have a suggestion for a small feature. The reason for adding these 
conversions would be to prevent mistakes and a small utilitarian gain.

real degToRad(real deg)
{
     return deg * PI / 180;
}

real radToDeg(real rad)
{
     return (180 * rad) / PI;
}


Or as Derek Parnell sugested (although I don't understand the 
operational difference here, but the top one did originally read float 
instead of real.

enum
{
    fPI_180 = PI / 180.0L;
    f180_PI = 180.0L / PI;
}

T degToRad(T)(T deg)
{
	return cast(T)(cast(real)deg * fPI_180);
}

T radToDeg(T)(T rad)
{
	return cast(T)(cast(real)rad * f180_PI);
}


Perhaps also gradToRad etc. Or gonToRad sice the gon is meant to be the 
proper ISO unit. People don't seem to use Grad much though.



More information about the Digitalmars-d mailing list