In article <0b414429-74ee-45dd-9465-c87e98c36...@googlegroups.com>, "Mark H. Harris" <harrismh...@gmail.com> wrote:
> On Friday, February 28, 2014 3:03:25 PM UTC-6, Marko Rauhamaa wrote: > > > > Marko > > ... and between me and you, here is a snip from dmath.py from the atan(x) > function: > > if (n**2 < D(1)): > a = __atan__(n) > elif (n == D(1)): > a = gpi/4 > elif (n == D(-1)): > a = -(gpi/4) > elif (n < D(-1)): > a = __atan__Lt_neg1__(n) > else: > a = __atan__Gt_1__(n) > > This if--elif--else is not only ugly, its just not readable either, and > besides that, its not elegant, nor is it humanly helpful... its does > work though, and its absolutely necessary. ugh. > > First, its not immediately clear what it does. Well, there isn't just one > atan(x) routine, there are at least four of them, depending on whether > you're a purist, and they must be selected. This kind of stuff is pretty common in numerical code. Depending on the sign/magnitude/quadrant/whatever of the argument, you'll want to use one of several algorithms to minimize roundoff error, etc. But, how would this be any nicer with switch? -- https://mail.python.org/mailman/listinfo/python-list