But it isn't just a number. It's an angle. That conveys meaning. Angles have multiple representations for example. In Radians and Degrees, and who knows what else. Hence the Math::Angle class has a method "degrees" and a method "radians". Converting a degree value to radians:
say 75°.radians; # yes the ° is a custom constructor. alternatively Ma
+th::Angle.new(degrees=>75).radians;
Also it behaves like a number where it makes sense.
ok 75° < Math::Angle.new(radians => pi);
Or even
ok 75° + 75° == 150°;
holli
You can lead your users to water, but alas, you cannot drown them.
| [reply] [d/l] [select] |
Angles have multiple representations for example. In Radians and Degrees.
The same reasoning holds for any magnitude (as for instance those representing length, time, weight, etc.), and well, you could define an algebra where magnitudes carry their units and make a lot of interesting things with it, like checking that your operations are consistent and that you don't add meters to seconds, for instance.
But just doing it for angles, well...
and who knows what else.
Yes, exactly, what else?
The only interesting thing I can think of is to avoid rounding errors. For instance, computers can not represent 90degrees in radians, just an approximation. Math::Angle could overload trigonometric operations and compute then using the degrees representation, without converting to radians first... but well, that's a daunting (and slow) task!
Update: s/degradians/degrees/
| [reply] |
| [reply] [d/l] |
where magnitudes carry their units and make a lot of interesting things with it, like checking that your operations are consistent and that you don't add meters to seconds, for instance.
That's what I did in school in Physics, to help being sure I did use the right formula. The probability of getting the correct units with a wrong formula is very low, at least at school :-)
| [reply] |