I also use scalars but have employed the 'use constant' construct
which seems made for this, see attached. Not sure if handling of units
is required or if settling on one system (e.g. SI) is sufficient.
Christian
On 3/05/2010, at 4:10 PM, Karl Glazebrook wrote:
I use scalars,
here is my private library
Karl
<Constants.pm>
On 03/05/2010, at 2:02 PM, Craig DeForest wrote:
I like using either UPPER CASE or CamelCase, to distinguish from
other
scalars.
I suggest at least:
Pi 3.14159265358979....
RaDeg Pi/180
RaMin Pi/180/60
RaSec Pi/180/3600
SecPerHour 3600
SecPerDay 86400
SecPerYear 31557600
E 2.7182818284590452.... (How do you put CamelCase on e?
All caps?)
Ln2 0.6931471805599453.... (for HWHM conversion with
Gaussians)
I like the idea of just putting them in scalars (perhaps as 0-
dimensional PDLs?) for the low access overhead (subs or objects can
get quite expensive). Memory is free on that scale these days. (who
needs log(2) in a toaster?)
Most of the other magic numbers I end up using seem to be unit
conversions, thus not relevant here...
On May 2, 2010, at 6:46 AM, Chris Marshall wrote:
I was reviewing outstanding issues for our
upcoming PDL CPAN developers release and
came upon:
http://sourceforge.net/tracker/?func=detail&aid=2787823&group_id=612&atid=350612
regarding adding basic math constants to PDL.
If you have any numerical constants you calculate
to use with PDL and any preference on their
implementation style (sub, scalar, object,...)
please rsvp to the list for discussion.
e.g.
I'm always calculating Pi
I prefer a perl scalar implementation
so I don't have to play games with
string interpolation.
Lower case is nice for ease of
typing. Upper case is useful in
that "constants" are often upcased
a la C macros.
Thanks,
Chris
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
--
Christian Soeller PhD Dept. of Physiology +64 9 3737599 x82770
University of Auckland Auckland, New Zealand fax +64 9 3737499
package PDL::Constants;
use strict;
require Exporter;
our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
# TODO: units via attributes and unit conversion!
@ISA = qw(Exporter);
@EXPORT = qw[
PI
AVOGADRO
FARADAY
R
E0
H
C
KB
];
use constant PI => 4 * atan2 1, 1;
use constant AVOGADRO => 6.0221367e23; # particles per mol
use constant FARADAY => 96500; # C/mol
use constant R => 8.314; # J/(K*mol)
use constant E0 => 1.60219e-19; # C
use constant H => 6.6262e-34; # Js
use constant C => 3e8; # m/s
use constant KB => 1.3807e-23; # J/K
1;
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl