Functional programming
Chris Angelico
rosuav at gmail.com
Tue Mar 4 08:01:01 EST 2014
On Tue, Mar 4, 2014 at 10:47 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Not even close. I'd like to see the compiler that can work out for itself
> that this function is buggy:
>
> def sine_rule(side_a, side_b, angle_a):
> """Return the angle opposite side_b."""
> return math.sin(side_b/side_a)*angle_a
>
>
> If you don't remember your Sine Rule from trigonometry, that's okay.
> Trust me, the function is badly wrong. It's rubbish really.
I'm not entirely sure what it's trying to do, but you're taking the
sine of a ratio. That... seems wrong, gut-feeling-wise. You take the
sine of an angle and get a ratio, or the arcsine of a ratio and get an
angle. Also, trig functions apply only to right triangles, so the
other angle is either going to be 90°-angle_a or 90°, depending on
whether you want the angle opposite the hypotenuse or not.
But it's years since I studied any of that.
ChrisA
More information about the Python-list
mailing list