home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Perl CookbookPerl CookbookSearch this book

2.11. Calculating More Trigonometric Functions

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;


Library Navigation Links

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