I use scalars,

here is my private library

Karl


=head1



Module KGB::Constants



Define useful physical & astronomical constants



Constants defined:



Mathematical: $Pi $deg $arcsec



Physical: $k $G $h $c $e $m_p $m_e $eps_0 $mu_0 $sigma_B



Astronomical: $M_sun $R_sun $L_sun $pc $au $Mpc $yr



(All defined in S.I. units and angles in radians)



Created by Karl Glazebrook Mar 19th 2002



=cut



package KGB::Constants;



require Exporter;

@ISA    = qw( Exporter );

@EXPORT = qw( $Pi $deg $arcsec  $k $G $h $c $e $m_p $m_e $eps_0 $mu_0 $sigma_B

$M_sun $R_sun $L_sun $pc $au $Mpc $yr);



# Misc mathematical constants



$Pi = 4.0*atan2(1,1);	      



# Various angles expressed in radians



$deg = $Pi/180.0;



$arcsec = $deg / 3600;



# Now my Physical Constants (all S.I.)



$k = 1.3806503E-23;

$G = 6.673E-11;

$h = 6.62606876E-34;

$c = 2.99792458E8;

$e = 1.602176462E-19;   # Elem charge

$m_p = 1.67262158E-27;  # mass proton

$m_e = 9.10938188E-31;  # mass electron

$eps_0 = 8.854187817E-12; # electric constant

$mu_0 = 4E-7 * $Pi;       # magnetic constant

# Stefan-Bolztmann constant

$sigma_B = (8 * $Pi**5 * $k**4 / (15 * ($h * $c)**3))*$c/4;



# Now add Astronomical Constants (S.I.)



$M_sun = 1.989E30;

$R_sun = 6.95508E8;

$L_sun = 3.845E26;

$pc    = 3.086E16;

$au    = 149.597871E9;

$Mpc   = 1E6 * $pc;

$yr    = 365.24219 * 3600 * 24;



# Done

1;





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

Reply via email to