Perl | Useful Math functions
In Perl, sometimes there is a need to solve various expressions that contain some mathematical operations. These mathematical operations can be performed with the use of various inbuilt-functions.
#!/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"; |
chevron_right
filter_none
Some useful functions for mathematical operations in Perl are listed below:
| Function | Description |
|---|---|
| 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 |
Recommended Posts:
- Perl | Subroutines or Functions | Set - 2
- Perl | List Functions
- Perl | Useful String functions
- Perl | Subroutines or Functions
- Perl | Useful Hash functions
- Perl | Useful Array functions
- Perl | File I/O Functions
- Perl | Useful File-handling functions
- Perl | Math::BigInt->from_bin() method
- Perl | Math::BigInt->bzero() method
- Perl | Math::BigInt->from_hex() method
- Perl | Math::BigInt->bneg() method
- Perl | Math::BigInt->config() method
- Perl | Math::BigInt->from_oct() method
- Perl | Math::BigInt->digit() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


