Perl Cd Bookshelf [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Perl Cd Bookshelf [Electronic resources] - نسخه متنی

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



2.11. Calculating More Trigonometric Functions


2.11.1. Problem


You want to
calculate values for trigonometric functions like sine, tangent, or
arc-cosine.

2.11.2. Solution




Perl provides only
sin, cos, and
atan2 as standard functions. From these, you can
derive tan and all other trig functions (if you're
intimately familiar with esoteric trig identities):

sub tan {
my $theta = shift;
return sin($theta)/cos($theta);
}

The POSIX module provides a wider
range of trig functions:

use POSIX;
$y = acos(3.7);

The standard Math::Trig module provides a complete set of functions
and supports operations on or resulting in complex numbers:

use Math::Trig;
$y = acos(3.7);

2.11.3. Discussion


The tan function will cause a division-by-zero
exception when $theta is π/2,
3π/2, and so on, because the cosine is 0 for these values.
Similarly, tan and many other functions from
Math::Trig may generate the same error. To trap these, use
eval:

eval {
$y = tan($pi/2);
} or return undef;

2.11.4. See Also


The sin, cos, and
atan2 functions in
perlfunc(1) and Chapter 29 of
Programming Perl; the documentation for the
standard Math::Trig module; we talk about trigonometry in the context
of imaginary numbers in
Recipe 2.14; we talk
about the use of eval to catch exceptions in
Recipe 10.12



2.10. Doing Trigonometry in Degrees, Not Radians2.12. Taking Logarithms




Copyright © 2003 O'Reilly & Associates. All rights reserved.

/ 875