13.3.1 Constants
13.3.1 Constants
The Math::Cephes gives access to a set of frequently used constants in scientific computation such as p, , , , , , ln 2, , etc. The following program simply prints out the values of some such constants. The constants can be either imported individually, or as a group, using the keyword :constants.
Program 13.2
#!/usr/bin/perl #file const.pl use Math::Cephes qw(:constants); print "PI = " . $Math::Cephes::PI . "\n"; print "PI over 2 = " . $Math::Cephes::PIO2 . "\n"; print "PI over 4 = " . $Math::Cephes::PIO4 . "\n"; print "SQRT of 2 = " . $Math::Cephes::SQRT2 . "\n"; print "SQRT of 2 over PI = " . $Math::Cephes::SQ2OPI . "\n"; print "2 over PI = " . $Math::Cephes::TWOOPI . "\n"; print "LOG to base E of 2 = " . $Math::Cephes::LOGE2 . "\n"; print "1 over LOG to base E of 2 = " . $Math::Cephes::LOG2E . "\n"; print "Machine Roundoff Error = " . $Math::Cephes::MACHEP . "\n"; print "Maximum log on the machine = " . $Math::Cephes::MAXLOG . "\n"; print "Minimum log on the machine = " . $Math::Cephes::MINLOG . "\n"; print "Maximum number on the machine = " . $Math::Cephes::MAXNUM . "\n";
The output of the program is mostly self-explanatory. The bottom of the program prints out certain machine-dependent constants that are useful for performing certain mathematical computation.
PI = 3.14159265358979
PI over 2 = 1.5707963267949
PI over 4 = 0.785398163397448
SQRT of 2 = 1.4142135623731
SQRT of 2 over PI = 0.797884560802865
2 over PI = 0.636619772367581
LOG to base E of 2 = 0.693147180559945
1 over LOG to base E of 2 = 1.44269504088896
Machine Roundoff Error = 1.11022302462516e-16
Maximum log on the machine = 709.782712893384
Minimum log on the machine = -745.133219101941
Maximum number on the machine = 1.79769313486232e+308
