TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:12095] Powers in Perl



On Mon, Jan 10, 2000 at 08:19:44PM -0600, Mike Hicks wrote:
> I have a little chunk of code below (taken pretty much verbatim from a C
> program) for calculating relative humidity using the current temperature
> and dewpoint (in degrees C)  The problem is that I need a function that
> will do powers of 10, but Perl (the language I'm writing this little
> program in) only has exp() for raising e to a power (as far as I know)
> 
> Does anyone either know a good trick to use or a function that I may
> have missed?  Thanks
> 
>     {
>       my ($esat, $esurf, $temp, $dewp)
>       $temp = $self->{C_TEMP};
>       $dewp = $self->{C_DEW};
>       
>       $esat = 6.11 * pow(10.0, (7.5 * $temp) / (237.7 + $temp)); 
>       $esurf = 6.11 * pow(10.0, (7.5 * $dewp) / (237.7 + $dewp));
>      
>       $self->{HUMIDITY} = sprintf("%3.f",(esurf/esat) * 100));
>     }

sub pow {
   return(exp(log($_[0]) * $_[1]));
}

Have fun (if at all possible),
-- 
Its name is Public Opinion.  It is held in reverence. It settles everything.
Some think it is the voice of God.  Loyalty to petrified opinion never yet
broke a chain or freed a human soul.     ---Mark Twain
-- Eric Hopper (hopper@omnifarious.mn.org  http://omnifarious.mn.org/~hopper) --

PGP signature