Re: Several Perl Questions - Nov. 5, 2013

Discussion in 'Perl Misc' started by Peter J. Holzer, Nov 5, 2013.

  1. On 2013-11-05 18:43, Henry Law <> wrote:
    > On 05/11/13 06:16, E.D.G. wrote:
    >> Are there modules for any Perl versions that enable Perl to do faster
    >> calculations?

    >
    > The version of your code that I looked at makes repeated calls to "pi",
    > like this (for example):
    >
    >> $sunlatrads = $sunlat*2*pi/360;
    >> $sunlonrads = $sunlon*2*pi/360;
    >> $moonlatrads = $moonlat*2*pi/360;
    >> $moonlonrads = $moonlon*2*pi/360;

    >
    > Pi is evaluated (presumably each time) within Math::Complex using the
    > atan() function.


    No,

    use Math::Trig;
    my $pi = pi;

    compiles to:

    use Math::Trig;
    my $pi = 3.1415926535897931;

    While technically this is a function call, the compiler is smart enough
    to notice that it evaluates to a constant value and can be inlined.

    (However, the compiler won't optimize “$sunlatrads = $sunlat*2*pi/360â€
    to “$sunlatrads = $sunlat*(2*pi/360)â€: You have to set the parentheses
    explicitely if you want that (and it will save you two ops at runtime).

    hp

    --
    _ | Peter J. Holzer | Fluch der elektronischen Textverarbeitung:
    |_|_) | | Man feilt solange an seinen Text um, bis
    | | | | die Satzbestandteile des Satzes nicht mehr
    __/ | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel
     
    Peter J. Holzer, Nov 5, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charlton Wilbur

    Re: Several Perl Questions - Nov. 5, 2013

    Charlton Wilbur, Nov 5, 2013, in forum: Perl Misc
    Replies:
    3
    Views:
    140
    Charlton Wilbur
    Nov 11, 2013
  2. John Black

    Re: Several Perl Questions - Nov. 5, 2013

    John Black, Nov 5, 2013, in forum: Perl Misc
    Replies:
    0
    Views:
    130
    John Black
    Nov 5, 2013
  3. Peter J. Holzer

    Re: Several Perl Questions - Nov. 5, 2013

    Peter J. Holzer, Nov 5, 2013, in forum: Perl Misc
    Replies:
    3
    Views:
    148
    Peter J. Holzer
    Nov 7, 2013
  4. Tim McDaniel

    Re: Several Perl Questions - Nov. 5, 2013

    Tim McDaniel, Nov 5, 2013, in forum: Perl Misc
    Replies:
    0
    Views:
    167
    Tim McDaniel
    Nov 5, 2013
  5. Justin C
    Replies:
    0
    Views:
    116
    Justin C
    Nov 6, 2013
Loading...

Share This Page