TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [TCLUG:12095] Powers in Perl
You might want to try the exponentiation operator: **
EX: 2**3 is 8
(-2)**(-3) is 1/8
Mike Hicks [hick0088@tc.umn.edu] 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));
> }
>
> --
> _ _ _ _ _ ___ _ _ _ ___ _ _ __ You're not Dave. Who are
> / \/ \(_)| ' // ._\ / - \(_)/ ./| ' /(__ you?
> \_||_/|_||_|_\\___/ \_-_/|_|\__\|_|_\ __)
> [ Mike Hicks | http://umn.edu/~hick0088/ | mailto:hick0088@umn.edu ]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tclug-list-unsubscribe@mn-linux.org
> For additional commands, e-mail: tclug-list-help@mn-linux.org
--
Clay Fandre
cfandre@maddog.mn-linux.org
Twin Cities Linux Users Group
http://www.mn-linux.org