📜  珀尔 |有用的数学函数

📅  最后修改于: 2022-05-13 01:55:06.288000             🧑  作者: Mango

珀尔 |有用的数学函数

在 Perl 中,有时需要求解包含一些数学运算的各种表达式。可以使用各种内置函数来执行这些数学运算。

#!/usr/bin/perl 
    
# Initialising some values for the 
# parameter of the exp function 
$A = 0; 
$B = 1; 
  
# Calling the exp function 
$E = exp $A; 
$F = exp $B; 
   
# Getting the value of "e" raised to the 
# power of the given parameter. 
print "$E\n"; 
print "$F\n"; 
  
# Calculating square root using sqrt() 
$square_root = sqrt(64); 
    
# Printing the result 
print "Squareroot of 64 is: $square_root"; 

下面列出了 Perl 中一些用于数学运算的有用函数:

FunctionDescription
exp()Calculates “e” raised to the power of the real number taken as the parameter
hex()Converts the given hexadecimal number ( of base 16 ) into its equivalent decimal number ( of base 10 ).
srand()Helps rand() function to generate a constant value each time the program is run
sqrt()Used to calculate the square root of a number
oct()Converts the octal value passed to its respective decimal value
rand()Returns a random fractional number between 0 and the positive number value passed to it, or 1 if no value is specified
log()Returns the natural logarithm of value passed to it. Returns $_ if called without passing a value
int()Returns the integer part of given value. It returns $_ if no value provided
sin()Used to calculate sine of a VALUE or $_ if VALUE is omitted
cos()Used to calculate cosine of a VALUE or $_ if VALUE is omitted
atan2()Used to calculate arctangent of Y/X in the range -PI to PI.
abs()Returns the absolute value of its argument