On 2/28/11 12:49 AM, Walter Bright wrote:
Colin Wallace wrote:
When using trigonometric functions, they all deal with radians. So
I've been having to do lots of converting. Converting is very
straightforward, but I still think it would be nice if there were some
built in functions for dealing with other units than radians. I think
a system that looked like what is used for the Duration struct in
core.time would make things more readable. The code for taking the
sine of a number measured in degrees could look like:
sin!"degrees"(45)
rather than
sin(45*PI/180)
I appreciate the suggestion, but suspect that adding a parallel set of
trig functions that do nothing more than multiply the arg by a constant
is more cognitive load for the user than benefit.
Agreed. What would add value is a units library that refuses calls to
e.g. trig functions unless the user specifically inserts a conversion.
That is, instead of
sin!"degrees"(x);
you'd use:
sin(to!"degrees"(x));
That way the conversion remains explicit but is hoisted out of the
multitude of math functions.
Andrei