Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^2: Perl oddities

by merlyn (Sage)
on Mar 01, 2005 at 18:05 UTC ( #435546=note: print w/ replies, xml ) Need Help??

in reply to Re: Perl oddities
in thread Perl oddities

sin, cos, and atan2 are "primitive" functions. From those, all other forward and reverse functions can be trivially derived.

The overhead of calling a subroutine is tiny compared to the overhead of computing the sin or cos, I would imagine.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Comment on Re^2: Perl oddities
Re^3: Perl oddities
by talexb (Canon) on Mar 01, 2005 at 19:01 UTC
      sin, cos, and atan2 are "primitive" functions.

    Well, once you have a routine for sin, then cos is the same thing, but pi/2 sooner. And I'm fairly sure that's the way it's implemented in the libraries.

    Using atan2 to do an inverse sin or cos is a bit of a walk in the park, but essentially I guess you have to find the 'Y' value once you have the 'X', then submit both to atan2, and that will give you the angle you're looking for.

    That's a nice brain exercise right after lunch.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      I suspect on most CPUs, it just uses the sin and cos opcodes of the native CPU. Implementing sin in terms of cos (or vice-versa) is just asking for problems, like the well-known results being a little off, since pi/2 cannot be exactly represented as a float (or as anything else in finite RAM).

Re^3: Perl oddities
by Anonymous Monk on Mar 02, 2005 at 13:17 UTC
    I know. But you can do away with either sin or cos as well - they are the same primitive, just shifted a quarter of a phase. That of course doesn't mean tan couldn't be present. After all, Perl gives us push, pop, shift and unshift, when they can all be trivially implemented using splice. Perl is a rich language, and any minimal approach is, to quote brian, what I consider exceptions to normal Perl thinking. Normal Perl thinking is "programmer convenience". A minimalistic approach isn't programmer convenience.

      My sense is that push/pop/shift/unshift are much more frequently used than the trig functions. On that basis, it makes Huffman sense to provide the convenience of the push, etc. functions while declining to provide a fuller set of trig functions.

        You can only explain that with "Huffman" if the save space of 'tan' actually allows you to do something else. Besides, for your reasoning to really work, you'd have to sacrifice one of sin or cos. The analogue would really be having 'splice', 'push' and 'unshift', but not 'pop' or 'shift'. ;-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://435546]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2014-07-26 19:36 GMT
Find Nodes?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:

    Results (178 votes), past polls