in reply to Re^2: RFC: Math::Triangle (Perl 6)
in thread RFC: Math::Triangle (Perl 6)

That is because you think Perl 5

Not really. I was actually thinking in a mathematical way.

I didn't mean overkill as inefficiency from a computational point of view, but overkill as introducing a new concept for something that is just a number.

Replies are listed 'Best First'.
Re^4: RFC: Math::Triangle (Perl 6)
by holli (Abbot) on Sep 18, 2017 at 13:16 UTC
    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.
      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/

        Isn't there a degree scale that uses 400° instead of 360°?


        holli

        You can lead your users to water, but alas, you cannot drown them.
        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 :-)