Perl Numeric functions perl 数学函数

Perl Functions by Category

sqrt EXPR

sqrt

Return the positive square root of EXPR. If EXPR is omitted, uses $_. Works only for non-negative operands unless you've loaded the Math::Complex module.

返回 EXPR 的正平方根。 如果省略 EXPR,则使用 $_。 仅适用于非负操作数,除非您已加载 Math::Complex 模块。

 1 $ print sqrt(4);
 2 Took 0 seconds.
 3 1                                                                                                                       
 4 $ 2
 5 Took 0.000326871871948242 seconds.
 6 $ print sqrt(-4);
 7 Took 0.000407934188842773 seconds.
 8 Runtime error: Can‘t‘ take sqrt of -4 at (eval 696) line 5.
 9 $ use Math::Complex;
10 Took 0.0199921131134033 seconds.
11 $ print sqrt(-4);
12 Took 0.000523805618286133 seconds.
13 1                                                                                                                       
14 $ 2i
sin EXPR
sin

Returns the sine of EXPR (expressed in radians). If EXPR is omitted, returns sine of $_.

For the inverse sine operation, you may use the Math::Trig::asin function, or use this relation:

返回 EXPR 的正弦值(以弧度表示)。 如果省略 EXPR,则返回 $_ 的正弦值。

对于反正弦运算,您可以使用 Math::Trig::asin 函数,或使用以下关系:

sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) }
1 $ asin 3;
2 Took 0 seconds.
3 1.5707963267949-1.76274717403909i
4  $ sin 3;
5 Took 0 seconds.
6 0.141120008059867 
 1 $ $caller;
 2 Took 0 seconds.
 3 Compile error: Global symbol "$caller" requires explicit package name at (eval 713) line 5.
 4 BEGIN not safe after errors--compilation aborted at (eval 713) line 5.
 5 $ $FuncLib_SYC_INTERFACE::caller;
 6 Took 0 seconds.
 7 $ print $FuncLib_SYC_INTERFACE;
 8 Took 0.0099940299987793 seconds.
 9 Compile error: Global symbol "$FuncLib_SYC_INTERFACE" requires explicit package name at (eval 715) line 5.
10 BEGIN not safe after errors--compilation aborted at (eval 715) line 5.
11 $ print $FuncLib_SYC_INTERFACE::caller;
12 Use of uninitialized value $FuncLib_SYC_INTERFACE::caller in print at (eval 716) line 5.
13 Took 0.00053715705871582 seconds.
14 1                                                                                                                       $ caller(FucLib_TNT_SYC_INTERFACE);
15 Took 0 seconds.
16 Compile error: Bareword "FucLib_TNT_SYC_INTERFACE" not allowed while "strict subs" in use at (eval 717) line 5.
17 $ caller('FucLib_TNT_INTERFACE');
18 Argument "FucLib_TNT_INTERFACE" isn't numeric in caller at (eval 718) line 5.
19 Took 0.000524997711181641 seconds.
20 [
21   "Lexical::Persistence",
22   "C:/TurboLIFT/Perl512/site/lib/Lexical/Persistence.pm",
23   340,
24   "Devel::REPL::Plugin::Packages::DefaultScratchpad::__ANON__",
25   1,
26   1,
27   undef,
28   undef,
29   1538,
30   "UUUUUUUUUUUUUU\25",
31   undef
32 ]
33 $   

 

posted @ 2021-12-20 19:31  boowii  阅读(88)  评论(0编辑  收藏  举报